Hi, is there a way I can show the sum and mean (in proc means) horizontally of a dataset? Eg.
Have
Type Var1 Var2
A 3 5
A 5 1
B 2 2
B 4 6
Want
Type Stat_name Var1 Var2
A Sum 8 6
A Mean 4 3
B Sum 6 8
B Mean 3 4
Thanks
Isn't that what proc summary does? e.g.:
proc summary data=have sum mean nway;
class type;
var var1 var2;
output out=want (drop=_type_ _freq_ rename=(_stat_=stat_name));
run;
Thanks Art, this is great but it doesn not provide the sum. It only shows : N / MIN / MAX / MEAN / STD
proc summary data=have sum mean nway;
class type;
var var1 var2;
output out=want sum=mean= / autoname ;
run;
No, but you can use PROC TRANSPOSE to fix it.
ods output summary=want2;
proc means data=have mean sum nway stackodsoutput;
class type ;
var var1-var2 ;
output out=want ;
run;
proc transpose data=want2 out=want name=stat_name;
by type ;
id variable ;
run;
data have; input Type $ Var1 Var2 ; cards; A 3 5 A 5 1 B 2 2 B 4 6 ; run; proc sql; create table want as select type,'Sum' as stat_name length=10,sum(var1) as var1,sum(var2) as var2 from have group by type union select type,'Mean' as stat_name length=10,mean(var1) as var1,mean(var2) as var2 from have group by type order by 1,2 desc; quit;
Xia Keshan
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.