Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mf_verifymacvars.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Checks if a set of macro variables exist / contain values.
4  @details Writes ERROR to log if abortType is SOFT, else will call %mf_abort.
5  Usage:
6 
7  %let var1=x;
8  %let var2=y;
9  %put %mf_verifymacvars(var1 var2);
10 
11  Returns:
12  > 1
13 
14  <h4> Dependencies </h4>
15  @li mf_abort.sas
16 
17  @param verifyvars space separated list of macro variable names
18  @param makeupcase= set to YES to convert all variable VALUES to
19  uppercase.
20  @param mAbort= Abort Type. Default is SOFT (writes err to log).
21  Set to any other value to call mf_abort (which can be configured to abort in
22  various fashions according to context).
23 
24  @warning will not be able to verify the following variables due to
25  naming clash!
26  - verifyVars
27  - verifyVar
28  - verifyIterator
29  - makeUpcase
30 
31  @version 9.2
32  @author Allan Bowe
33 
34 **/
35 
36 
37 %macro mf_verifymacvars(
38  verifyVars /* list of macro variable NAMES */
39  ,makeUpcase=NO /* set to YES to make all the variable VALUES uppercase */
40  ,mAbort=SOFT
41 )/*/STORE SOURCE*/;
42 
43  %local verifyIterator verifyVar abortmsg;
44  %do verifyIterator=1 %to %sysfunc(countw(&verifyVars,%str( )));
45  %let verifyVar=%qscan(&verifyVars,&verifyIterator,%str( ));
46  %if not %symexist(&verifyvar) %then %do;
47  %let abortmsg= Variable &verifyVar is MISSING;
48  %goto exit_err;
49  %end;
50  %if %length(%trim(&&&verifyVar))=0 %then %do;
51  %let abortmsg= Variable &verifyVar is EMPTY;
52  %goto exit_err;
53  %end;
54  %if &makeupcase=YES %then %do;
55  %let &verifyVar=%upcase(&&&verifyvar);
56  %end;
57  %end;
58 
59  %goto exit_success;
60  %exit_err:
61  %if &mAbort=SOFT %then %put %str(ERR)OR: &abortmsg;
62  %else %mf_abort(mac=mf_verifymacvars,type=&mabort,msg=&abortmsg);
63  %exit_success:
64 
65 %mend;