I would like to basically use the following code
%let year = measles1900 - measles2001;
versus listing out each year
%let year = measles1900 measles1901 measles1902 measles1903 measles1904 measles1905 measles1906 measles1907 measles1908 measles1909 ...
and so on.
Do I need to use a command along the lines of %nstr, etc., am I able to use an array somehow, or am I out of luck and need to resort to listing all 102 years?
@Reeza I have measles(YEAR) as different datasets.
After that let statement, I want to do a proc summary as follows:
proc summary data=&year;
var countvalue;
output out=total_&year sum=;
run;
so that I can get column totals for the variable countvalue by year.
Maybe a CALL EXECUTE structure?
data range;
do yr=1900 to 2001 by 1;
year = put(yr,4.);
call execute
(
"
proc summary data=measles" || year || ";
var countvalue;
output out=total_" || year || " sum=;
run;
"
);
end;
run;
I assume that you want to
So you will have to collect all the data first.
%let indata=measles1900-measles2001;
data v_measles/view=v_measles;
set &indata indsname=table;
year=input(substr(table,length(table)-3),4.0);
run;
I did the data collection as a view, as there is no reason to duplicate the actual data. You can now do your summary on the data step view:
proc summary data=v_measles nway;
var countvalue;
class year;
output out=total sum=;
run;
I am assuming your proc summery is working, please find the code.
%macro runit;
%let years = measles1900 measles1901 measles1902 measles1903 measles1904 measles1905 measles1906 measles1907 measles1908 measles1909;
%let y_count=%sysfunc(countw(&years, ' '));
%do i=1 %to &y_count.;
%let year=%sysfunc(scan(&years,&i));
%put &=year;
proc summary data=&year;
var countvalue;
output out=total_&year sum=;
run;
%end;
%mend runit;
%runit;
Please let us know if it worked for you.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.