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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.