BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Greek
Obsidian | Level 7

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;

answerFrequencyPercentCumulative FrequencyCumulative Percent
Maybe325325
No325650
Yes65012100

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

answerFrequencyPercentCumulative FrequencyCumulative Percent
Maybe325325
Uncertain00325
No325650
Yes65012100

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19
data classdata;
   input answer :$10.;
  
cards;
Yes
No
Maybe
Uncertain
;;;;
  
run;
proc print;
  
run;
data example;
   input answer :$10. @@;
   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;
   class answer;
   output out=freq(drop=_type_);
   run;
proc print;
  
run;
proc freq data=freq order=data;
   tables answer;
   weight _freq_ / zeros;
  
run;

Capture.PNG

View solution in original post

5 REPLIES 5
Ksharp
Super User

Simple Data Step ?

Code: Program

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

Greek
Obsidian | Level 7

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.

Reeza
Super User

Look into proc tabulate and PRELOADFMT

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

25400 - Use of PRELOADFMT with PROC TABULATE

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

data_null__
Jade | Level 19
data classdata;
   input answer :$10.;
  
cards;
Yes
No
Maybe
Uncertain
;;;;
  
run;
proc print;
  
run;
data example;
   input answer :$10. @@;
   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;
   class answer;
   output out=freq(drop=_type_);
   run;
proc print;
  
run;
proc freq data=freq order=data;
   tables answer;
   weight _freq_ / zeros;
  
run;

Capture.PNG
Greek
Obsidian | Level 7

Thank you all so much! Smiley Happy

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1742 views
  • 7 likes
  • 4 in conversation