Help using Base SAS procedures

More grouping options in proc summary?

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

More grouping options in proc summary?

I have some data that I am analyzing using proc summary.  The following example produces output that is really close to what I need:

data input;

   input source sex $ weight;

   datalines;

176 M 2240

176 F 1814

177 M 2380

177 F 1910

178 M 2190

178 F 1790

179 M 2250

179 F 1850

;

run;

proc summary data=input;

   class source sex;

   var weight;

   output out=summary mean=weight cv=cv n=no;

run;

proc print data=summary noobs;

run;

I would like to group some of the class data together so that the output includes the "176+177" lines shown below:

sourcesex_TYPE__FREQ_weight   cv  no
.           0     8   2053 11.4592 8
F    1     4   1841  2.8350 4
M    1     4   2265  3.5777 4
  176           2     2   2027 14.8608 2
  177           2     2   2145 15.4937 2
  176+177       2     4   2075 15.1234 4
  178           2     2   1990 14.2132 2
  179           2     2   2050 13.7972 2
  176  F    3     1   1814   .     1
  176  M    3     1   2240   .     1
  177  F    3     1   1910   .     1
  177  M    3     1   2380   .     1
  176+177  F    3     1   1860
  176+177  M    3     1   2310
  178  F    3     1   1790   .     1
  178  M    3     1   2190   .     1
  179  F    3     1   1850   .     1
  179  M    3     1   2250   .     1

The only way I can think of doing that is to use several data steps to combine the values for several of my sources and then append the combined data to my original data before running through proc summary.  Is there a more elegant approach?


Accepted Solutions
Solution
‎02-05-2013 12:17 PM
Super User
Posts: 17,831

Re: More grouping options in proc summary?

Use a multilabel format in proc means (rather than summary). I think most of the code will stay the same though between the two procedures.

Base SAS(R) 9.3 Procedures Guide, Second Edition

View solution in original post


All Replies
Solution
‎02-05-2013 12:17 PM
Super User
Posts: 17,831

Re: More grouping options in proc summary?

Use a multilabel format in proc means (rather than summary). I think most of the code will stay the same though between the two procedures.

Base SAS(R) 9.3 Procedures Guide, Second Edition

Respected Advisor
Posts: 3,777

Re: More grouping options in proc summary?

MULTILABEL formats work in PROC SUMMARY.  PROC MEANS and PROC SUMMARY are the same program.

Super User
Posts: 17,831

Re: More grouping options in proc summary?

Thanks, are they always interchangeable?

Respected Advisor
Posts: 3,777

Re: More grouping options in proc summary?

The defaults are different. 

The documentation for PROC SUMMARY is basically "see proc means"

Base SAS(R) 9.3 Procedures Guide, Second Edition

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 170 views
  • 3 likes
  • 3 in conversation