Hi,
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.
Thank you.
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:
http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/
Thank you. I think it's time for me to learn macro
I am analyzing # of visits yearly rather than across 15 years.
For example.
# of visits in year 2000 = 1.3 million
# of visits in year 2001 = 1.4million
# of visits in year 2002 = 1.5 million
etc
I will be analyzing more than just # of visits but everything will be looked at yearly.
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.