%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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.