Skip to content

Commit

Permalink
fix: removing unnecessary cond flags in mf_abort, adding abort logic …
Browse files Browse the repository at this point in the history
…in mp_csv2ds
  • Loading branch information
allanbowe committed Nov 8, 2020
1 parent d51be73 commit f6cec01
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 50 deletions.
71 changes: 46 additions & 25 deletions all.sas
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ options noquotelenmax;
@version 9.2
@author Allan Bowe
**/ /** \cond */
**/

%macro mf_getengine(libref
)/*/STORE SOURCE*/;
Expand All @@ -419,9 +419,7 @@ options noquotelenmax;

&engine

%mend;

/** \endcond *//**
%mend;/**
@file
@brief Returns the size of a file in bytes.
@details Provide full path/filename.extension to the file, eg:
Expand Down Expand Up @@ -1933,29 +1931,50 @@ Usage:
@version 9.2
@author Allan Bowe
<h4> Dependencies </h4>
@li mp_abort.sas
@li mf_existds.sas
**/
%macro mp_csv2ds(inref=0,outds=0,baseds=0,view=NO);
%if &inref=0 %then %do;
%put %str(ERR)OR: the INREF variable must be provided;
%let syscc=4;
%abort;
%end;
%if %superq(outds)=0 %then %do;
%put %str(ERR)OR: the OUTDS variable must be provided;
%let syscc=4;
%return;
%end;
%if &baseds=0 %then %do;
%put %str(ERR)OR: the BASEDS variable must be provided;
%let syscc=4;
%return;
%end;
%if %sysfunc(exist(&BASEDS)) ne 1 & %sysfunc(exist(&BASEDS,VIEW)) ne 1 %then %do;
%put %str(ERR)OR: the BASEDS dataset (&baseds) needs to be assigned, and to exist;
%let syscc=4;
%return;
%end;
%mp_abort(iftrue=( &inref=0 )
,mac=&sysmacroname
,msg=%str(the INREF variable must be provided)
)
%mp_abort(iftrue=( %superq(outds)=0 )
,mac=&sysmacroname
,msg=%str(the OUTDS variable must be provided)
)
%mp_abort(iftrue=( &baseds=0 )
,mac=&sysmacroname
,msg=%str(the BASEDS variable must be provided)
)
%mp_abort(iftrue=( &baseds=0 )
,mac=&sysmacroname
,msg=%str(the BASEDS variable must be provided)
)
%mp_abort(iftrue=( %mf_existds(&baseds)=0 )
,mac=&sysmacroname
,msg=%str(the BASEDS dataset (&baseds) needs to be assigned, and to exist)
)
/* count rows */
%local hasheader; %let hasheader=0;
data _null_;
if _N_ > 1 then do;
call symputx('hasheader',1,'l');
stop;
end;
infile &inref;
input;
run;
%mp_abort(iftrue=( &hasheader=0 )
,mac=&sysmacroname
,msg=%str(No header row in &inref)
)
/* get the variables in the CSV */
data _data_;
Expand Down Expand Up @@ -2020,7 +2039,9 @@ data &outds
;
infile &inref dsd firstobs=2;
input &instat;
drop &dropvars;
%if %length(&dropvars)>0 %then %do;
drop &dropvars;
%end;
run;
%mend;/**
Expand Down
6 changes: 2 additions & 4 deletions base/mf_getengine.sas
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@version 9.2
@author Allan Bowe
**/ /** \cond */
**/

%macro mf_getengine(libref
)/*/STORE SOURCE*/;
Expand All @@ -42,6 +42,4 @@

&engine

%mend;

/** \endcond */
%mend;
65 changes: 44 additions & 21 deletions base/mp_csv2ds.sas
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,50 @@
@version 9.2
@author Allan Bowe
<h4> Dependencies </h4>
@li mp_abort.sas
@li mf_existds.sas
**/

%macro mp_csv2ds(inref=0,outds=0,baseds=0,view=NO);
%if &inref=0 %then %do;
%put %str(ERR)OR: the INREF variable must be provided;
%let syscc=4;
%abort;
%end;
%if %superq(outds)=0 %then %do;
%put %str(ERR)OR: the OUTDS variable must be provided;
%let syscc=4;
%return;
%end;
%if &baseds=0 %then %do;
%put %str(ERR)OR: the BASEDS variable must be provided;
%let syscc=4;
%return;
%end;
%if %sysfunc(exist(&BASEDS)) ne 1 & %sysfunc(exist(&BASEDS,VIEW)) ne 1 %then %do;
%put %str(ERR)OR: the BASEDS dataset (&baseds) needs to be assigned, and to exist;
%let syscc=4;
%return;
%end;

%mp_abort(iftrue=( &inref=0 )
,mac=&sysmacroname
,msg=%str(the INREF variable must be provided)
)
%mp_abort(iftrue=( %superq(outds)=0 )
,mac=&sysmacroname
,msg=%str(the OUTDS variable must be provided)
)
%mp_abort(iftrue=( &baseds=0 )
,mac=&sysmacroname
,msg=%str(the BASEDS variable must be provided)
)
%mp_abort(iftrue=( &baseds=0 )
,mac=&sysmacroname
,msg=%str(the BASEDS variable must be provided)
)
%mp_abort(iftrue=( %mf_existds(&baseds)=0 )
,mac=&sysmacroname
,msg=%str(the BASEDS dataset (&baseds) needs to be assigned, and to exist)
)

/* count rows */
%local hasheader; %let hasheader=0;
data _null_;
if _N_ > 1 then do;
call symputx('hasheader',1,'l');
stop;
end;
infile &inref;
input;
run;
%mp_abort(iftrue=( &hasheader=0 )
,mac=&sysmacroname
,msg=%str(No header row in &inref)
)

/* get the variables in the CSV */
data _data_;
Expand Down Expand Up @@ -115,7 +136,9 @@ data &outds
;
infile &inref dsd firstobs=2;
input &instat;
drop &dropvars;
%if %length(&dropvars)>0 %then %do;
drop &dropvars;
%end;
run;

%mend;

0 comments on commit f6cec01

Please sign in to comment.