Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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 Reports a failure in the log and returns 0. It never aborts: an
5 mf_ macro returns a value, and ending the step here would leave the caller
6 unable to see that value or to report the failure itself.
7 Usage:
8
9 %let var1=x;
10 %let var2=y;
11 %put %mf_verifymacvars(var1 var2);
12
13 Returns:
14 > 1
15
16 @param [in] verifyvars Space separated list of macro variable names
17 @param [in] makeupcase= (NO) Set to YES to convert all variable VALUES to
18 uppercase.
19 @param [in] mAbort= (SOFT) Retained for backwards compatibility. The macro
20 no longer aborts on any value - a failure is written to the log and 0 is
21 returned, so the caller decides what to do with it.
22
23 @note will not be able to verify the following variables due to
24 naming clash!
25 - verifyVars
26 - verifyVar
27 - verifyIterator
28 - makeUpcase
29
30 @version 9.2
31 @author Allan Bowe
32
33**/
34
35%macro mf_verifymacvars(
36 verifyVars /* list of macro variable NAMES */
37 ,makeUpcase=NO /* set to YES to make all the variable VALUES uppercase */
38 ,mAbort=SOFT
39)/*/STORE SOURCE*/;
40
41 %local verifyIterator verifyVar abortmsg;
42 %do verifyIterator=1 %to %sysfunc(countw(&verifyVars,%str( )));
43 %let verifyVar=%qscan(&verifyVars,&verifyIterator,%str( ));
44 %if not %symexist(&verifyvar) %then %do;
45 %let abortmsg= Variable &verifyVar is MISSING;
46 %goto exit_err;
47 %end;
48 %if %length(%trim(&&&verifyVar))=0 %then %do;
49 %let abortmsg= Variable &verifyVar is EMPTY;
50 %goto exit_err;
51 %end;
52 %if &makeupcase=YES %then %do;
53 %let &verifyVar=%upcase(&&&verifyvar);
54 %end;
55 %end;
56
57 %goto exit_success;
58 %exit_err:
59 %put &abortmsg;
60 0
61 %return;
62 %exit_success:
63 1
64
65%mend mf_verifymacvars;