07-24-2016 11:58 PM - edited 07-24-2016 11:59 PM
I'm analyzing data from year 2000 - 2015 with each year having its own data file. Instead of repeating all the procedures yearly, is there a shortcut function where I can analyze all the years with one code? I can try to merge all the files but each file contains around 80 million observations.
All the variables are the same for each year.
07-25-2016 12:49 AM
There isn't a function but you can create a macro. Macro in the simplest form generate code.
The macro below, called sample, runs proc means on the provided dataset. Note how the parameter is referenced within the macro (&datain).
Options MPRINT SYMBOLGEN; %macro sample(datain); Proc means data = &datain; Run; %mend; %sample(sashelp.class); %sample(sashelp.cars);
See a tutorial here:
07-25-2016 12:50 AM
07-25-2016 01:02 AM
I am analyzing # of visits yearly rather than across 15 years.
# of visits in year 2000 = 1.3 million
# of visits in year 2001 = 1.4million
# of visits in year 2002 = 1.5 million
I will be analyzing more than just # of visits but everything will be looked at yearly.
07-25-2016 01:24 AM
To run the statistics for each year, you can do
%macro stats; %do year = 2000 %to 2015; proc means data=mylib.data_&year; ....... run; %end; %mend; %stats;
Now, if you have the year in the dataset in a variable, you could do
%macro stats; data work.statview/view=work.statview; set %do year = 2000 %to 2015; mylib.data&year %end; ; run; proc means data=work.statview; by yearvar; ..... run; %mend; %stats;
07-25-2016 04:18 AM
As an alternative, you could do it in one simple datastep:
data tmp; do i=2000 to 2015; call execute(cats('proc means data=year_',i,'; var age; output out=yr',i,'; run;')); end; call execute('data want; set yr:; run;'); run;