Hi all,
I got a problem. I want to create a sas macro and the parameters are also macro variables, so how can I pass these macro variables into macro?
Thanks.
for example:
%let a=c1,c2,c3,c4,c5;
%let b=d1,d2,d3,d4,d5;
%macro input(data1,data2);
... &data1;(I want to use a here)
... &data2;(I want to use b here)
%mend;
%input(?,?); (what should I fill in here)
@ttxq wrote:
yes, I want to know how to pass them into the Macro.
Thanks for your replying.
Pass the names not the value. Then you don't have to worry about quoting in the macro call. Also you can't name a macro %INPUT.
26 %let a=c1,c2,c3,c4,c5;
27 %let b=d1,d2,d3,d4,d5;
28 %macro xinput(data1,data2);
29 %put NOTE: &&&data1 &&&data2;
30 %mend;
31 %xinput(a,b);
NOTE: c1,c2,c3,c4,c5 d1,d2,d3,d4,d5
Do you need to pass them in? They exist and you can use them in the macro as shown.
yes, I want to know how to pass them into the Macro.
Thanks for your replying.
Ok, add two extra parameters to your macro and then pass the two variable lists.
You'll need to mask the commas or use a different separator. I think using a different separator is easier but if you want comma's for some reason, you can mask them using the techniques here:
@ttxq wrote:
yes, I want to know how to pass them into the Macro.
Thanks for your replying.
Pass the names not the value. Then you don't have to worry about quoting in the macro call. Also you can't name a macro %INPUT.
26 %let a=c1,c2,c3,c4,c5;
27 %let b=d1,d2,d3,d4,d5;
28 %macro xinput(data1,data2);
29 %put NOTE: &&&data1 &&&data2;
30 %mend;
31 %xinput(a,b);
NOTE: c1,c2,c3,c4,c5 d1,d2,d3,d4,d5
Placing commas inside a variable is often a poor idea. If you intend to use it as a macro parameter it will fail because the macro variable resolves with the commas and then each value after a comma is treated as a another parameter. Generally this results in the number of parameters passed not matching the macro definition.
%let a=c1,c2,c3,c4,c5;
What kind of macro are you building that requires the commas?
And this may help
%let a = c1 c2 c3 c4;
%let ab = %sysfunc(translate(&a,',',' '));
%put &ab;
if you place exactly one space between elements.
Or learn to use the macro quoting functions.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.