Hi All,
I have a keyword parameter macro: param2 takes a list of variables like var1, var2, var3, var4, var5, var6
%macro test(param1=, param2=); %let varlist=%sysfunc(translate(%sysfunc(upcase(¶m2)),%str(,),%str( ))); %put &=varlist; %mend test;
The above macro is saved in a file test.sas
Now, I want to include this macro in another macro and call it as shown:
%macro test2(param1=,param2=); #include "C:\Practice\test.sas"; %test(param1=,param2=); %mend;
But, it's not working. Please, advise me how to call this macro?
Log:
103 %macro test2(param1=,param2=); 104 %include "C:\Practice\test.sas"; 105 %test(param1=,param2=); 106 %mend; 107 108 %test2(param1=name, param2=var1 var2 var3 var4 var5 var6) ERROR: The function UPCASE referenced by the %SYSFUNC or %QSYSFUNC macro function has too few arguments. WARNING: Argument 1 to function TRANSLATE referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range. VARLIST=
Your example macros are confusing because they have parameters they don't use.
But I think your question is how to pass the INPUT to a macro into the call to another macro.
The answer is simple. Just expand the parameter where you want to use it (the same thing you do to use the parameter for anything else).
%macro test2(param1=,param2=);
%test(param1=¶m1,param2=¶m2);
%mend;
Perhaps you are confused because the two macros are using the same names for the parameters. That does not matter in the context of running %TEST the reference to &PARAM1 is to the LOCAL macro variable that is created by defining PARAM1 as a parameter to the macro. And in the context of %TEST2 the same thing applies. &PARAM1 refers to the parameter named PARAM1 passed into the call to %TEST2. When you have local macro variables with names that are the same as other macro variables that exist in outer scopes (including the GLOBAL scope) then the LOCAL macro variable hides the access to the others.
Your example macros are confusing because they have parameters they don't use.
But I think your question is how to pass the INPUT to a macro into the call to another macro.
The answer is simple. Just expand the parameter where you want to use it (the same thing you do to use the parameter for anything else).
%macro test2(param1=,param2=);
%test(param1=¶m1,param2=¶m2);
%mend;
Perhaps you are confused because the two macros are using the same names for the parameters. That does not matter in the context of running %TEST the reference to &PARAM1 is to the LOCAL macro variable that is created by defining PARAM1 as a parameter to the macro. And in the context of %TEST2 the same thing applies. &PARAM1 refers to the parameter named PARAM1 passed into the call to %TEST2. When you have local macro variables with names that are the same as other macro variables that exist in outer scopes (including the GLOBAL scope) then the LOCAL macro variable hides the access to the others.
Actually, the macro that I am using takes two keyword parameters, but since I can't mention all the code, hence I am just giving a sample code after testing it that the error is coming for which I need help.
I have tried as per your suggestion and it worked. Thank you very much.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.