BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

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

5 REPLIES 5
art297
Opal | Level 21

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;

podarum
Quartz | Level 8

Thanks Art,  this is great but it doesn not provide the sum.  It only shows :  N / MIN / MAX / MEAN / STD

podarum
Quartz | Level 8

proc summary data=have sum mean nway;

class type;

  var var1 var2;

  output out=want  sum=mean= / autoname ;

run;

Tom
Super User Tom
Super User

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;

Ksharp
Super User
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

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!

What is Bayesian Analysis?

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.

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
  • 5 replies
  • 2493 views
  • 0 likes
  • 4 in conversation