Hi,
I want to change a variable in a data.
But I want to do the same job for multiple files in a directory.
I kind of feel that I can do this efficiently if I use macro, but I do not know exactly becuase I am just a beginner of SAS macro.
The SAS code for one file is..
data test;
set pars.prod11_beer;
COLUPC = 1*UPC
drop UPC;
run;
Any advice or suggetion from you would be greatly appreciated!
Thanks!
Hi ,
Please try the below macro
%macro dir(name=,file=,var=,var2=);
data &name;
set pars..&file;
&var= 1*&var2
drop &var2;
run;
%mend;
%dir(name=test, file=prod11_beer,var=COLUPC,var2=UPC);
Hope this helps
Thanks,
Jagadish
Hi ,
Please try the below macro
%macro dir(name=,file=,var=,var2=);
data &name;
set pars..&file;
&var= 1*&var2
drop &var2;
run;
%mend;
%dir(name=test, file=prod11_beer,var=COLUPC,var2=UPC);
Hope this helps
Thanks,
Jagadish
Thanks.
But it did not work well..
I got the error message below.
Do you have any idea why this happened?
Hi
Please remove the additional . from pars..&file, there should be a single . like this
pars.&file
Please try and let me know the output.
Thanks,
Jagadish
Thank you so much!
It worked beautifully!
Jin-Hee Huh
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.