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 AND 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> SAS Macros </h4>
15  @li mf_abort.sas
16 
17  @param [in] verifyvars Space separated list of macro variable names
18  @param [in] makeupcase= (NO) Set to YES to convert all variable VALUES to
19  uppercase.
20  @param [in] mAbort= (SOFT) Abort Type. When SOFT, simply writes an err
21  message to the log.
22  Set to any other value to call mf_abort (which can be configured to abort in
23  various fashions according to context).
24 
25  @warning will not be able to verify the following variables due to
26  naming clash!
27  - verifyVars
28  - verifyVar
29  - verifyIterator
30  - makeUpcase
31 
32  @version 9.2
33  @author Allan Bowe
34 
35 **/
36 
37 
38 %macro mf_verifymacvars(
39  verifyVars /* list of macro variable NAMES */
40  ,makeUpcase=NO /* set to YES to make all the variable VALUES uppercase */
41  ,mAbort=SOFT
42 )/*/STORE SOURCE*/;
43 
44  %local verifyIterator verifyVar abortmsg;
45  %do verifyIterator=1 %to %sysfunc(countw(&verifyVars,%str( )));
46  %let verifyVar=%qscan(&verifyVars,&verifyIterator,%str( ));
47  %if not %symexist(&verifyvar) %then %do;
48  %let abortmsg= Variable &verifyVar is MISSING;
49  %goto exit_err;
50  %end;
51  %if %length(%trim(&&&verifyVar))=0 %then %do;
52  %let abortmsg= Variable &verifyVar is EMPTY;
53  %goto exit_err;
54  %end;
55  %if &makeupcase=YES %then %do;
56  %let &verifyVar=%upcase(&&&verifyvar);
57  %end;
58  %end;
59 
60  %goto exit_success;
61  %exit_err:
62  %put &abortmsg;
63  %mf_abort(iftrue=(&mabort ne SOFT),
64  mac=mf_verifymacvars,
65  msg=%str(&abortmsg)
66  )
67  0
68  %return;
69  %exit_success:
70  1
71 
72 %mend mf_verifymacvars;