Weird PROC FREQ trick

3

Default PROC FREQ output looks like this:

Proc_1

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.

Proc_2Suppose you want your output to look like the above, except with totals, like this:

Proc_3

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.

PROC_FREQ

Share

About Author

Jim Simon

Principal Technical Training Consultant

Jim Simon is a principal instructor and course developer for SAS Education. Jim has a bachelor's degree from UCLA and a master's degree from California State University at Northridge. Prior to joining the SAS Irvine office in 1988, Jim was an instructor at Ventura College and a SAS programmer at The Medstat Group in Santa Barbara. Jim's areas of specialization include the DATA step, application development, web enablement, and the SAS macro language. A native of Southern California, Jim enjoys anything in the warm California sun. On weekends, Jim loves jumping in his Corvette, turning up the stereo, and cruising Pacific Coast Highway, top down, South to Laguna Beach or North to his old home town, Santa Barbara.

3 Comments

  1. Rick Wicklin

    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.

  2. Anders Skollermo on

    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!"

Back to Top