Hello,
I want to create variables and dataset with a macro. Part of the name of those is one of the parameter of this macro.
When the parameter is located at the end of the name, it works.
Example:
%macro test(year);
data work.bd&year;
variable&years=variable;
run;
%mend test;
%test(2007);
How can I do the same, but with the parameter at the beginningof the name? This doesn't work because the parameter is not recognise:
%macro test(year);
data work.&yearbd;
&yearvariable=variable;
run;
%mend test;
%test(2007);
Thanks
The first letter of a dataset name or variable can't be a digit, it is illegal.
I don't understand why would you want do that.You can use a underline before it to make it legal.
or use options validvarname=any ; to make it happen.
options validvarname=any ;
%macro test(year);
data work._&year.bd ;
"&year.variable"n=1; output;
run;
%mend test;
%test(2007);
Message was edited by: xia keshan
The first letter of a dataset name or variable can't be a digit, it is illegal.
I don't understand why would you want do that.You can use a underline before it to make it legal.
or use options validvarname=any ; to make it happen.
options validvarname=any ;
%macro test(year);
data work._&year.bd ;
"&year.variable"n=1; output;
run;
%mend test;
%test(2007);
Message was edited by: xia keshan
Thanks. In fact, the problem was the . between the two terms.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.