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

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller

View solution in original post

6 REPLIES 6
Astounding
PROC Star

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.

PaigeMiller
Diamond | Level 26
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. 

--
Paige Miller
cbt2119
Obsidian | Level 7

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?

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Tom
Super User Tom
Super User
proc means data=sashelp.class;
  class sex;
  var height;
  ways 0 1;
run;

image.png

cbt2119
Obsidian | Level 7
Thanks, this works well too!

SAS Innovate 2025: Register Now

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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 1878 views
  • 2 likes
  • 4 in conversation