Help using Base SAS procedures

Proc freq with one response option

Reply
Occasional Contributor
Posts: 8

Proc freq with one response option

Hi,

 

I am using SAS 9.4. I have a variable yes/no response options but all of answers were yes. I am using ods tables in proc freq to export the output to a data set and them export it (with DDE) to excel. My excel table is set up with both Yes and No so I should have Yes = 100% and No=0% in excel. Except SAS in the proc freq ods command only exports the 100%. Is there a way for me to export the output in a new data set that contains both Yes and No?

 

Thanks.

Super User
Posts: 7,771

Re: Proc freq with one response option

Posted in reply to mmjohnson

PROC FREQ will only report (and output) values that are actually present in the dataset. If you need to have other values in your output dataset, you could create a default dataset containing all values and then do a join to complete your output dataset

data ynresponse;
input response $3.;
cards;
no
yes
;
run;

data wanted_result;
merge
  result (in=a)
  ynresponse (in=b)
;
by response;
if not b then count = 0; * avoids missing values;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,023

Re: Proc freq with one response option

Posted in reply to mmjohnson
data have;
input response $3.;
cards;
yes
yes
yes
yes
;
run;
data temp;
response='no';
run;

data want;
 set have(in=ina) temp;
 weight=ina;
run;
proc freq data=want;
table response ;
weight weight/zeros;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 244 views
  • 2 likes
  • 3 in conversation