BookmarkSubscribeRSS Feed
UniversitySas
Quartz | Level 8

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

 

 

3 REPLIES 3
ed_sas_member
Meteorite | Level 14

Hi @UniversitySas 

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,

Ksharp
Super User

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;
Astounding
PROC Star

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 778 views
  • 1 like
  • 4 in conversation