With SAS 94M4, I have a macro parameter value that contains the trigger for the macro processor (%). I need this parameter value to be triggered at macro compile time, however at SAS execution time, I need a quoting function that does not attempt to resolve what appears as a macro reference. At least that is how I understand the timing of things here. The SAS log is below, followed by the program. Any insights are appreciated along with how masking/unmasking and compile/execution timing for Macro quoting. I found Ian Whitlock's paper to be a great deal of help at: http://www2.sas.com/proceedings/sugi28/011-28.pdf options mtrace mlogic mprint;
18 %let ds = WORK.mm_var;
19
20 %macro getargument(paramname=);
21 %* Get count for key values;
22 %* Get key values;
23
24 proc sql noprint;
25 select count(key) into :key_count
26 from &ds.;
27
28 select key into :key_values separated by "+"
29 from &ds.;
30 quit;
31
32 %put ===> key values are &key_values;
33 %* Test to see of the paramvalue is valid;
34
35 %if %sysfunc(indexw(&key_values, "¶mname", "+")) = 0 %then %do;
36 %put ===> The parameter "¶mname" is not valid.;
37 %put ===> Exiting the Macro.;
38 %goto exit;
39 %end;
40
41 %* Test to see if the paramname value is <blank>;
42
43 %if %sysevalf(%superq(paramname)=,boolean) %then %do;
44 %put ===> The paramname value is "<blank>" existing MACRO;
45 %goto exit;
46 %end;
47
48 %* Test to see if the paramname value contains <blank> characters;
49 %* If true, replace <blank> with underscore (_);
50
51 %if %sysfunc(find(%bquote(¶mname),%str( ))) > 0 %then %do;
52
53 %let paramname1=%sysfunc(translate(%bquote(¶mname),%str(_),%str( )));
54 proc sql noprint;
55 select value into :val¶mname1
56 from &ds
57 where soundex(key) = soundex("¶mname");
58 quit;
59
60 %put ========================<>==========================;
61 %put ===> The Key is: ¶mname and value is %unquote(%str(&&val¶mname1)) <===;
62
63 %goto exit;
64 %end;
65
66 proc sql noprint;
67 select value into :val
68 from &ds
69 where soundex(key) = soundex("¶mname");
70 quit;
71
72 %put ========================<>==========================;
73 %put ===> The Key is: ¶mname and value is %trim(&val) <===;
74
75 %exit:
76 %mend;
77 run;
78 %getargument(paramname=trips up macro);
MLOGIC(GETARGUMENT): Beginning execution.
MLOGIC(GETARGUMENT): Parameter PARAMNAME has value trips up macro
MPRINT(GETARGUMENT): proc sql noprint;
MPRINT(GETARGUMENT): select count(key) into :key_count from WORK.mm_var;
MPRINT(GETARGUMENT): select key into :key_values separated by "+" from WORK.mm_var;
MPRINT(GETARGUMENT): quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
MLOGIC(GETARGUMENT): %PUT ===> key values are &key_values
===> key values are kpi+EVAL1+benchmark+workdir+inputfile1+input file forsas+trips up macro
MLOGIC(GETARGUMENT): %IF condition %sysfunc(indexw(&key_values, "¶mname", "+")) = 0 is FALSE
MLOGIC(GETARGUMENT): %IF condition %sysevalf(%superq(paramname)=,boolean) is FALSE
MLOGIC(GETARGUMENT): %IF condition %sysfunc(find(%bquote(¶mname),_ _)) > 0 is TRUE
MLOGIC(GETARGUMENT): %LET (variable name is PARAMNAME1)
MPRINT(GETARGUMENT): proc sql noprint;
MPRINT(GETARGUMENT): select value into :valtrips_up_macro from WORK.mm_var where soundex(key) =
soundex("trips up macro");
MPRINT(GETARGUMENT): quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
MLOGIC(GETARGUMENT): %PUT ========================<>==========================
========================<>==========================
MLOGIC(GETARGUMENT): %PUT ===> The Key is: ¶mname and value is %unquote(_&&val¶mname1_)
<===
WARNING: Apparent invocation of macro _SIGN not resolved.
WARNING: Apparent invocation of macro _SIGN not resolved.
===> The Key is: trips up macro and value is /home/sas/file_with_%_sign.sas
<===
MLOGIC(GETARGUMENT): %GOTO EXIT (label resolves to EXIT).
MLOGIC(GETARGUMENT): Ending execution.
79
80 run; The program is: options mprint mlogic mtrace;
DATA mm_var;
length key $ 128
value $ 1024;
INPUT KEY $ & @21 VALUE $;
DATALINES4;
kpi 80
EVAL1 90
benchmark 70
workdir /tmp/x
inputfile1 /tmp/x/input/file1.csv
input file forsas /MM/RTemp/tmp.Fi8jheBOAu/input/5a4e0eaad8e0c3b8d782609f
trips up macro /home/sas/file_with_%_sign.sas
;;;;
RUN;
proc print;run;
options mtrace mlogic mprint;
%let ds = WORK.mm_var;
%macro getargument(paramname=);
%* Get count for key values;
%* Get key values;
proc sql noprint;
select count(key) into :key_count
from &ds.;
select key into :key_values separated by "+"
from &ds.;
quit;
%put ===> key values are &key_values;
%* Test to see if the paramvalue is valid;
%if %sysfunc(indexw(&key_values, "¶mname", "+")) = 0 %then %do;
%put ===> The parameter "¶mname" is not valid.;
%put ===> Exiting the Macro.;
%goto exit;
%end;
%* Test to see if the paramname value contains <blank> characters;
%* If true, replace <blank> with underscore (_);
%if %sysfunc(find(%bquote(¶mname),%str( ))) > 0 %then %do;
%let paramname1=%sysfunc(translate(%bquote(¶mname),%str(_),%str( )));
proc sql noprint;
select value into :val¶mname1
from &ds
where soundex(key) = soundex("¶mname");
quit;
%put ========================<>==========================;
%put ===> The Key is: ¶mname and value is %unquote(%str(&&val¶mname1)) <===;
%goto exit;
%end;
proc sql noprint;
select value into :val
from &ds
where soundex(key) = soundex("¶mname");
quit;
%put ========================<>==========================;
%put ===> The Key is: ¶mname and value is %trim(&val) <===;
%exit:
%mend;
run;
%getargument(paramname=trips up macro);
run;
... View more