Hi SAS Community,
I have searched the knowledge base and Google, but can't see to find the answer to what seems to be a simple question. Is it possible to run a single proc means/summary or proc tabulate statement and get the class level summary statistics for a variable as well as the overall summary statistics? I have to run two separate procedures, to get both - one with the class statement and one omitting the class statement. I don't want to have to output it to a data set either. Does anyone know a more efficient way to do this? Example of the longhand code I run below.
Thanks,
Cara
proc means data=workdata; class binaryvar ; var continuousvar; run;
proc means data=workdata; var continuousvar; run;
@cbt2119 wrote:
Is there a way to do it without using the output statement?
Yes, use PROC MEANS instead of PROC SUMMARY, and the WAYS or TYPES command. But without the OUTPUT statement, you get output to HTML or to the LISTING or some other print destination. With the OUTPUT statement, you get a data set.
... is there an option in the class statement that also computes the overall statistics, like the totals rows and columns in proc freq?
Yes, the WAYS or TYPES command will force the overall statistics to be printed out.
If you take the top PROC MEANS, and add an OUTPUT statement (with all the necessary details), the output data set will contain just what you are asking for.
proc summary data=workdata;
class binaryvar;
var continuousvar;
output out=_stats_ mean=continuousvar_mean;
run;
Look up the documentation for PROC SUMMARY, please see the NWAY option, as well as the TYPES command and the WAYS command in PROC SUMMARY, these give you complete control over what combinations of CLASS variables are to be included in the output.
Is there a way to do it without using the output statement? Like is there an option in the class statement that also computes the overall statistics, like the totals rows and columns in proc freq?
@cbt2119 wrote:
Is there a way to do it without using the output statement?
Yes, use PROC MEANS instead of PROC SUMMARY, and the WAYS or TYPES command. But without the OUTPUT statement, you get output to HTML or to the LISTING or some other print destination. With the OUTPUT statement, you get a data set.
... is there an option in the class statement that also computes the overall statistics, like the totals rows and columns in proc freq?
Yes, the WAYS or TYPES command will force the overall statistics to be printed out.
proc means data=sashelp.class;
class sex;
var height;
ways 0 1;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.