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;
input answer $ @@;
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
Simple Data Step ?
data example;
input answer $ @@;
datalines;
Yes Yes Yes Yes Yes No Maybe Maybe Maybe No No Yes
run;
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
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.
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.
Thank you all so much!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.