I know there is an autoname feature in proc means,
but I was wondering if there were a simple way to do something like:
proc means data = have;
by date;
var first1-first10 second1-second10;
output out = table mean(first1-first10) = mean_(first1-first10);
Run;
I know the above code doesnt work, but instead of typing out
mean(first1-first10) = mean_first1 mean_first2 mean_first3....
Is there a quicker was to do this? Even if in a data step or proc sql?
I think /autoname wouldn't work here, because it would give me first1_mean, first2_mean ....
Thanks
I don't think that it is possible to achieve this in a PROC MEANS.
Here is an alternative approach:
proc means data = have;
by date;
var first1-first10 second1-second10;
output out = table mean= / autoname;
run;
%let statistic = Mean; /*Select one the following: Min Max Sum StdDev Mean*/
proc sql noprint;
select catt(name,"= &statistic._",scan(name,1,'_'))
into: newnames separated by " "
from dictionary.columns
where libname="WORK" and memname="TABLE" and find(name,"&statistic.")>0;
quit;
proc datasets lib=WORK nolist;
modify TABLE;
rename &newnames.;
quit;
Hope this helps.
Best,
You could rename them as this way.
data have;
date='xx';
input f1-f4;
cards;
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
;
proc summary data=have;
by date;
var f1-f4;
output out=want(rename=(f1-f4=mean_f1-mean_f4)) mean= ;
run;
It should be straightforward:
proc summary data=have;
var first1-first10 second1-second10;
output out=want mean=mean_first1-mean_first10 mean_second1-mean_second10;
run;
This is untested code, so see if it works for your data.
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.