Solved
Contributor
Posts: 48

# Proc Freq--All inclusive table

Good afternoon,

I have a question related to the tabular output of proc freq.

Let's say that I have the following survey question:

Do you like politics?

a) Yes

b) No

c) Maybe

d) Uncertain

In the event that one of the 4 options gets selected by nobody (say d), Proc freq will give me the following table (Code created for your convenience):

data example;

datalines;

Yes Yes Yes Yes Yes No Maybe Maybe Maybe No No Yes

run;

proc freq data=example;

run;

 answer Frequency Percent Cumulative Frequency Cumulative Percent Maybe 3 25 3 25 No 3 25 6 50 Yes 6 50 12 100

While I would like the missing 'd. Uncertain' to be recorded:

 answer Frequency Percent Cumulative Frequency Cumulative Percent Maybe 3 25 3 25 Uncertain 0 0 3 25 No 3 25 6 50 Yes 6 50 12 100

Do you know how can I make proc freq output the second table? If proc freq can't do it, do you have a different procedure in mind that can?

Thank you

Accepted Solutions
Solution
‎07-20-2015 03:34 PM
Posts: 3,852

## Re: Proc Freq--All inclusive table

data classdata;

cards;
Yes
No
Maybe
Uncertain
;;;;

run;
proc print;

run;
data example;
datalines;
Yes Yes Yes Yes Yes No Maybe Maybe Maybe No No Yes
run;
proc print;

run;
proc summary data=example nway classdata=classdata order=data;
output out=freq(drop=_type_);
run;
proc print;

run;
proc freq data=freq order=data;
weight _freq_ / zeros;

run;

All Replies
Super User
Posts: 10,784

## Re: Proc Freq--All inclusive table

Simple Data Step ?

### Code: Program

`data example;input answer \$ @@;datalines;Yes Yes Yes Yes Yes No Maybe Maybe Maybe No No Yesrun; ods output OneWayFreqs=temp;proc freq data=example ; tables answer/ cumcol;run;data want;length answer \$ 20; set temp; output; if _n_ eq 1 then do;  answer='Uncertain';  Frequency=0;Percent=0;output; end; drop Table F_answer;run;`

Xia Keshan

Contributor
Posts: 48

## Re: Proc Freq--All inclusive table

Hello Xia,

Thank you very much for your response. I was hoping for something less manual as I need to produce a large series of frequency tables and I am using macros, but this is certainly helpful. I will use it in a case-by-case basis.

Super User
Posts: 23,758

## Re: Proc Freq--All inclusive table

Look into proc tabulate and PRELOADFMT

There are probably more clear examples than this one, but its the documentation

25400 - Use of PRELOADFMT with PROC TABULATE

No matter what, you need some table or somewhere that has the full list of all options.

Solution
‎07-20-2015 03:34 PM
Posts: 3,852

## Re: Proc Freq--All inclusive table

data classdata;

cards;
Yes
No
Maybe
Uncertain
;;;;

run;
proc print;

run;
data example;
datalines;
Yes Yes Yes Yes Yes No Maybe Maybe Maybe No No Yes
run;
proc print;

run;
proc summary data=example nway classdata=classdata order=data;
output out=freq(drop=_type_);
run;
proc print;

run;
proc freq data=freq order=data;
weight _freq_ / zeros;

run;

Contributor
Posts: 48

## Re: Proc Freq--All inclusive table

Thank you all so much!

🔒 This topic is solved and locked.