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
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.
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;
@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 1144But 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?
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.
The PROC SUMMARY approach does provide column totals (and row totals).
@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"?
for reporting purposes. to report the individual categorical count and the tonal by category.
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.
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.
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.