I want to make a union of all datasets from 2010-2019 whcih are named like students_201001, students_201002....students_201012.....students_201905.
I was using a nested loop one for year and other for moth, but it is not working:
%macro join;
%Do i=2010 %to 2019;
%DO j=01 %TO 12;
data append_recov_&i&j;
set chi_perf.perf_chi_&i
run;
%end;
%end;
%mend;
%join;
Please help!
There's a much simpler way by using wildcards:
data want;
set students_201:;
run;
The iterative %DO loop will convert your values into numbers and then back to strings to assign to the loop variable.
So %DO j=01 %to 12 will set J to 1,2,3,4,5,6,7,8,9,10,11,12.
If you want to convert the values less than 10 to 2 digits try using the PUTN() function.
%do j=01 %to 12;
%let j=%sysfunc(putn(&j,z2.));
An easy way to get YYYYMM is to create a third macro variable:
%do y=2010 %to 2019;
%do m = 1 %to 12;
%let ym = %eval(&m + 100 * &y);
%put The year and month: &ym;
%end;
%end;
data want;
set students_201001 - students_201910 ;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.