Hi, I currently have a proc freq macro.
How do I separate these into separate proc freq's for each variable?
Note: I have 13 categorical variables and 2 numerical variables.
/*looping through all categorical variables for proc freq exports*/
%macro freq_loop;
%Do i=1 %to &num_cats.;
%let j=%scan(&cat_vars.,&i.);
proc freq data=&filetype._stacked order=freq;
table &j. / out=freqs_&j. ;
by year;
run;
PROC EXPORT DATA=freqs_&j.
OUTFILE="&results.\&filetype._ProcFreq_&date..csv"
dbms=xlsx replace;
sheet= "&j.";
RUN;
%end;
%mend;
%freq_loop;
/*looping through all numerical variables for proc means exports*/
%macro means_loop;
%Do i=1 %to &num_nums.;
%let j=%scan(&num_vars.,&i.);
proc means data=&filetype._stacked;
var &j.;
by year;
output out=means_&j. (where=(_STAT_ IN ("MIN", "MEAN", "MAX"))drop=_TYPE_ _FREQ_);
run;
PROC EXPORT DATA=means_&j.
OUTFILE="&results.\&filetype._ProcMeans_&date..csv"
dbms=xlsx replace;
sheet= "&j.";
RUN;
%end;
%mend;
%means_loop;
Thank you in advance,
Hello,
I am wondering how to take it out of the macro (a.k.a. the looping), group by year (I have a total of 12 years)
I want to write it out for example (I know this code is wrong):
proc freq cat_var ...
and thank you for the csv tip. I'll note it.
Something like this:
proc freq data=inputDatasetName;
table SingleVariable orListOfVarsSpaceDelimited;
run;
proc freq data=sashelp.class;
table sex age name;
table sex;
table age;
table sex*age;
run;
Maybe this tutorial would be helpful:
I'll try this out and will see if it works!
Thank you!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.