Default PROC FREQ output looks like this:
Suppose you don't want the two cumulative statistic columns above. No problem. Those can be suppressed with the NOCUM option on the TABLE statement, like this:
proc freq data=sashelp.shoes; table product / nocum; run; |
Now your output looks like this, but you lose the grand totals.
Suppose you want your output to look like the above, except with totals, like this:
No problem. Just export to Excel, right?
Sure, Excel can easily total up your columns, but you can just as easily do it in SAS, using this weird trick:
proc freq data=sashelp.shoes; table product / noprint out=mytable; run; |
The NORPINT option on the TABLE statement suppresses the PROC FREQ report. Instead, the OUT= option causes PROC FREQ to create an output dataset, WORK.MYTABLE.
proc print data=mytable noobs; sum count percent; run; |
Now, print the output dataset from PROC FREQ, using PROC PRINT with a SUM statement to total up the COUNT and PERCENT columns. No need to export to Excel!
Watch the SAS Training Post blog for more weird tricks.
3 Comments
I'm not sure why you call this a PROC FREQ trick. Suppressing output and writing results to a data set are standard operations for many SAS procedures, and there is nothing weird about the NOCUM option. Seems more like a PROC PRINT trick, since you are using PROC PRINT to add a summarization row.
Hi! There are 395 boots +..+ dresses. One unit increase makes a change of 0.253 percent. E.g. 51 men's dresses gives 12.914 percent. So perhaps the values should all be rounded to 1 decimal only.
A funny thing can then happen: Say, only three issues. 33 of each. 33.3 percent each. Now the sum of 33.3 + 33.3 + 33.3 is "of course" 100.00 percent.
If you do not like this "anomality" then one suitable value should be raised. It is not entirely easy in general to determine that in a good way. / Br Anders - "Retired, but not tired!"
Good point! Thanks, Anders!