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:
source | sex | _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?
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.
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.
MULTILABEL formats work in PROC SUMMARY. PROC MEANS and PROC SUMMARY are the same program.
Thanks, are they always interchangeable?
The defaults are different.
The documentation for PROC SUMMARY is basically "see proc means"
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.