D/All,
I have this proc summary to which i'm passing dynamic variables for classes and aggregations using a macro variable.
The challenge is i will not know which all class and aggregates variables are passed but i want below proc summary to be created. During execution the code should iterate thru number of aggregate vars, build and append to proc summary. I may pass just one aggregate var or a max of 10/12 vars.
%let var_classes = class1 class2 class3 class4 class5
%let var_aggregates = var1 var2 var3 var4;
proc summary data = in_data. noprint nonobs;
var &var_aggregates.;
class &var_classes.;
output out = imp1_out_data.
sum(var1)=
sum(var2)=
sum(var3)=
sum(var4)=
/autoname levels ways;
run;
Please note the variable names are not var1 var2 var3 var4 but will be actual names from the dataset. Only for illustration purpose i have used var1...4
Requesting experts to guide me on this.
Thanks a lot.
Rgds, Anil
The statistic(var-list) syntax is usually used when you want something different from all-vars-in-var-statement or if there is no var statement.
You could have written sum(&var_aggregates)= with or without VAR statement.
You may need to use macro logic as well.
Thanks Linus, I was too thinking of appending using a macro but then other experts suggested a much better shorter way which worked for my requirement.
You can code this , and sas will rename them for you.
output out = imp1_out_data sum= /autoname ;
Thank you Keshan.. Yes this also worked.
The statistic(var-list) syntax is usually used when you want something different from all-vars-in-var-statement or if there is no var statement.
You could have written sum(&var_aggregates)= with or without VAR statement.
Thank you so much for this simply short solution.. and I was wondering how do I iterate and append that piece of code down the proc summary.
I may come across a requirement where there could be variety of aggregations. Assuming if i define as in below example, var_aggregates and their method, how do i build the output script. The previous logic will not work for this.
%let var_classes = class1 class2 class3 class4 class5
%let var_aggregates = var1 var2 var3 var4;
%let var_aggregates_method = N sum mean max;
proc summary data = in_data. noprint nonobs;
var &var_aggregates.;
class &var_classes.;
output out = imp1_out_data.
N(var1)=
sum(var2)=
mean(var3)=
max(var4)=
/autoname levels ways;
run;
Any suggestions..?
Thanks a lot for this great help...
Rgds, Anil
If your macro variables were considered a user interface to an application I would not use parallel lists. I see parallel lists used all the time and I don't like them even when I use them.
I would prefer something like this both as a user and a developer.
%let stat_var_aggregates = n(var1)= sum(var2)= min(var3)= max(var4)=;
Very similar and the user can see exactly what is being requested.
If you do stick with parallel lists then a macro could be used to scan the lists and output a string derived from the words. This example assumes that the lists have equal number of words although scanning stops when list1 is out of words.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.