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