From f6cec012da90d277da042926c7ff46845d463f86 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sun, 8 Nov 2020 22:04:25 +0100 Subject: [PATCH] fix: removing unnecessary cond flags in mf_abort, adding abort logic in mp_csv2ds --- all.sas | 71 ++++++++++++++++++++++++++++--------------- base/mf_getengine.sas | 6 ++-- base/mp_csv2ds.sas | 65 ++++++++++++++++++++++++++------------- 3 files changed, 92 insertions(+), 50 deletions(-) diff --git a/all.sas b/all.sas index a6842292..ff0d23a8 100644 --- a/all.sas +++ b/all.sas @@ -399,7 +399,7 @@ options noquotelenmax; @version 9.2 @author Allan Bowe -**/ /** \cond */ +**/ %macro mf_getengine(libref )/*/STORE SOURCE*/; @@ -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: @@ -1933,29 +1931,50 @@ Usage: @version 9.2 @author Allan Bowe + +

Dependencies

+ @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_; @@ -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;/** diff --git a/base/mf_getengine.sas b/base/mf_getengine.sas index e396bc58..c76f63e5 100755 --- a/base/mf_getengine.sas +++ b/base/mf_getengine.sas @@ -22,7 +22,7 @@ @version 9.2 @author Allan Bowe -**/ /** \cond */ +**/ %macro mf_getengine(libref )/*/STORE SOURCE*/; @@ -42,6 +42,4 @@ &engine -%mend; - -/** \endcond */ \ No newline at end of file +%mend; \ No newline at end of file diff --git a/base/mp_csv2ds.sas b/base/mp_csv2ds.sas index dd43c25d..65e3db05 100644 --- a/base/mp_csv2ds.sas +++ b/base/mp_csv2ds.sas @@ -28,29 +28,50 @@ @version 9.2 @author Allan Bowe + +

Dependencies

+ @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_; @@ -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; \ No newline at end of file