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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2797 views
  • 0 likes
  • 4 in conversation