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

Hello,

I am doing a simple 2*2 proc freq.

 

proc freq data= pop order=freq;
       tables sex*severity /missing ;
run;

 i get an output wiht the totals

Frequency| Severe | Attenuated| Undetermed | Total
.                | 0           | 1               | 0                   | 1
MALE       | 371       | 183           | 34                 | 588
FEMALE  | 336       | 194           | 25                 | 555
Total          707         378             59                   1144

But when I specify an output dataset and a noprint option:

 

proc freq data= pop noprint order=freq;
       tables sex*severity /missing out=test(drop=percent) ;
run;

 

the output dataset test does not have the cumulative total. I tried a few options but none work.

Any idea what I need to specify to get the total to be added in the output dataset?

 

thanks

KC

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The idea of doing everything in one step sometimes leads people to very complicated or unworkable code that takes hours to get right.

 

You can run PROC SUMMARY to get the sums, and then PROC REPORT to make your nice report. You could also do it entirely in PROC REPORT. 

--
Paige Miller

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

You could get this using ODS OUTPUT. If there is a continuous variable in the data set, then PROC SUMMARY works as well.

 

ods output crosstabfreqs=freqs;
proc freq data=pop;
    tables sex*severity/missing;
run;

 

 

--
Paige Miller
ballardw
Super User

@Kc2 wrote:

Hello,

I am doing a simple 2*2 proc freq.

 

proc freq data= pop order=freq;
       tables sex*severity /missing ;
run;

 i get an output wiht the totals

Frequency| Severe | Attenuated| Undetermed | Total
.                | 0           | 1               | 0                   | 1
MALE       | 371       | 183           | 34                 | 588
FEMALE  | 336       | 194           | 25                 | 555
Total          707         378             59                   1144

But when I specify an output dataset and a noprint option:

 

proc freq data= pop noprint order=freq;
       tables sex*severity /missing out=test(drop=percent) ;
run;

 

the output dataset test does not have the cumulative total. I tried a few options but none work.

Any idea what I need to specify to get the total to be added in the output dataset?

 

thanks

KC


You can try

proc freq data= pop noprint order=freq;
       tables sex*severity /missing norow nocol nopercent ;
       ods output crasstabfreq=test;
run;

Which will have the row and column totals but I suspect not in a form you want.

 

 

It is dangerous to include "totals" inside a data set when not extremely well documented, ie. another variable such as the _TYPE_ variable in the ODS OUTPUT table that indicates whether the value is a cell, row, column or table total. 

 

Why do you need the totals in the data set?

Kc2
Quartz | Level 8 Kc2
Quartz | Level 8

I need to have the totals column so I am trying to do everything in one step..

 So far none of the solutions provided work so i will do calculated the total in a separate step.

 

 

PaigeMiller
Diamond | Level 26

The PROC SUMMARY approach does provide column totals (and row totals).

--
Paige Miller
ballardw
Super User

@Kc2 wrote:

I need to have the totals column so I am trying to do everything in one step..

 So far none of the solutions provided work so i will do calculated the total in a separate step.

 

 



 


WHY? Do "what everything in one step"?
Kc2
Quartz | Level 8 Kc2
Quartz | Level 8

for reporting purposes. to report the individual categorical count and the tonal by category.

PaigeMiller
Diamond | Level 26

The idea of doing everything in one step sometimes leads people to very complicated or unworkable code that takes hours to get right.

 

You can run PROC SUMMARY to get the sums, and then PROC REPORT to make your nice report. You could also do it entirely in PROC REPORT. 

--
Paige Miller
ballardw
Super User

Proc tabulate if you don't like the default proc freq appearance is also an option.

 

proc tabulate data=sashelp.class;
   class sex age;
   table sex='' all='Total',
         (age='' all='Total')*n=''
         /misstext=' ';
run;

Proc tabulate also has lots of appearance modification possibilities.

 

Jagadishkatam
Amethyst | Level 16

you could try

 

data want;
set pop;
output;
sex='Total';
severity ='Total';
output;
run;


proc freq data= want order=freq;
       tables sex*severity /missing out=test(drop=percent) ;
run;
Thanks,
Jag

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 11626 views
  • 2 likes
  • 4 in conversation