%macro uo;
%do i = 1 %to 9;
data a.nc;
%let setname = %scan(9 8 7 6 5 4 3 2 1, &i);
%if &i = 1 %then %do;
update a.data&setname (keep = v1 v2)
a.data10 (keep = v1 v2);
%end;
%else %if &i > 1 %then %do;
update a.nc
a.data&setname (keep = v1 v2);
%end;
by v1;
run;
%end;
%mend;
%uo;
I am studying some sas programs and cannot understand the %let, %scan. Can anybody help to explain in details.
Thanks a lot
The SAS Macro Reference is a great resource for questions about specific statements and functions:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543704.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#z3514scan.htm
Looks like they want SETNAME to go from 9 down to 1. Instead of the using that strange %SCAN() funciton they could have just used arithmetic to convert I to SETNAME.
%let setname=%eval(10-&i);
They could have alos just use SETNAME in the %DO loop direcly.
%do setname = 9 %to 1 %by -1;
data a.nc;
%if &setname=9 %then %do;
update a.data&setname (keep = v1 v2)
a.data10 (keep = v1 v2);
%end;
%else %do;
update a.nc
a.data&setname (keep = v1 v2);
%end;
by v1;
run;
%end;
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.