BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
walterwang
Obsidian | Level 7

I have the below data set. I want to use proc summary to get the summary like that

sextotal
1
2….
9
all

 

 

 

 

sexagetotal
11408563
12338258
13311091
14121462
15102785
1626971
178573
1817051
1920
213710
2312209
2412745
254205
26584
2715521
2929
91981
92108
9310
94459
95294
969
9735
98136
997901
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

 

This:

 

proc summary data=sashelp.class;
  class sex;
  var age;
  output out=want (rename=(age=age_sum) drop=_type_ _freq_) sum()=;
run;

 

 

Would get you some of the way, but then you need to get a bit more creative:

 

proc format;
  value $sex (multilabel)
    "M"="Male"
    "F"="Female"
    "M","F"="All";
run;

proc summary data=sashelp.class nway;
  class sex / mlf order=formatted;
  var age;
  format sex $sex.;
  output out=want (rename=(age=age_sum) drop=_type_ _freq_) sum()=;
run;

Will get you the summary unfortunately not in order, but you can fiddle around with the order= option with your data - you have not posted any test data in the form of a datastep and I am not here to type it in!

View solution in original post

5 REPLIES 5
andreas_lds
Jade | Level 19

Why proc summary? Proc report seems to be more fitting to get the desired output.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

 

This:

 

proc summary data=sashelp.class;
  class sex;
  var age;
  output out=want (rename=(age=age_sum) drop=_type_ _freq_) sum()=;
run;

 

 

Would get you some of the way, but then you need to get a bit more creative:

 

proc format;
  value $sex (multilabel)
    "M"="Male"
    "F"="Female"
    "M","F"="All";
run;

proc summary data=sashelp.class nway;
  class sex / mlf order=formatted;
  var age;
  format sex $sex.;
  output out=want (rename=(age=age_sum) drop=_type_ _freq_) sum()=;
run;

Will get you the summary unfortunately not in order, but you can fiddle around with the order= option with your data - you have not posted any test data in the form of a datastep and I am not here to type it in!

Reeza
Super User

Use PROC MEANS which will generate the total and overall summary. If this is for display, PROC TABULATE, MEANS, or FREQ are more appropriate.

 

proc means data=have noprint;
class sex; 
ways 0 1;
var total;
output out=want sum=Total;
run;

proc tabulate data=have;
class sex;
var total;
table (sex all), total='Total'*sum=''*f=12.;
run;
Astounding
PROC Star

All of this is possible.  In fact, all of this is easy.  But please tell us what you are trying to do.  What goes in the TOTAL column?  Do we ignore AGE and get the sum of the original TOTAL values?  Are we getting the average of the original TOTAL values instead of the sum?

 

The hardest part is writing a program when you don't know what you are trying to achieve.

walterwang
Obsidian | Level 7

It is hard to understand proc summary for different output. thanks guys.

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
  • 1218 views
  • 3 likes
  • 5 in conversation