Hi to All,
I am a new SAS user and I’m trying to produce the output below using the following set of codes, where the non-numeric outcomes are missing values, A=” Not Home” and R=” Refused.” The problem I’m having is that my SAS program displays the percent, cumulative frequency, cumulative percent of the missing variables. Is there a way to exclude both missing variables (A and R) in calculating these three measures and report them as missing values as in the table below?
Thank you.
Lear Alfonso
The FREQ Procedure
Cumulative Cumulative
q1 Frequency Percent Frequency Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Not home 2 . . .
Refused 1 . . .
1 3 42.86 3 42.86
2 3 42.86 6 85.71
3 1 14.29 7 100.00
Frequency Missing = 3
DATA survey;
MISSING A R;
INPUT id q1 $;
CARDS;
8401 2
8402 A
8403 1
8404 1
8405 2
8406 3
8407 A
8408 1
8408 R
8410 2
;
RUN;
Data surveyf;
set survey;
if q1='a' then q1='.';
if q1='r' then q1='.';
*;
proc format;
value $qf 'A' = 'Not Home' 'R' = 'Refused';
format q1 $qf.;
run;
proc freq data=surveyf;
format q1 $qf.;
tables q1 / missprint;
RUN;
quit;
My SAS output
|
Can you use .A and .R instead and treat the values as numerics?
Hi to All,
I am a new SAS user and I’m trying to produce the output below using the following set of codes, where the non-numeric outcomes are missing values, A=” Not Home” and R=” Refused.” The problem I’m having is that my SAS program displays the percent, cumulative frequency, cumulative percent of the missing variables. Is there a way to exclude both missing variables (A and R) in calculating these three measures and report them as missing values as in the table below?
Thank you.
Lear Alfonso
The FREQ Procedure
Cumulative Cumulative
q1 Frequency Percent Frequency Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Not home 2 . . .
Refused 1 . . .
1 3 42.86 3 42.86
2 3 42.86 6 85.71
3 1 14.29 7 100.00
Frequency Missing = 3
DATA survey;
MISSING A R;
INPUT id q1 $;
CARDS;
8401 2
8402 A
8403 1
8404 1
8405 2
8406 3
8407 A
8408 1
8408 R
8410 2
;
RUN;
Data surveyf;
set survey;
if q1='a' then q1='.';
if q1='r' then q1='.';
*;
proc format;
value $qf 'A' = 'Not Home' 'R' = 'Refused';
format q1 $qf.;
run;
proc freq data=surveyf;
format q1 $qf.;
tables q1 / missprint;
RUN;
quit;
My SAS output
|
While there are errors in your program, the errors don't affect the answer to your question. You can't get the table you want with PROC FREQ. You can get part-way there if you were to create Q1 as a numeric variable. MISSPRINT still gives you counts (not percents) for the missing values. (I can't test it right now, but you can try the program below.)
Here are some changes that might get you a bit closer:
data survey;
missing A R;
input id q1;
cards;
....... same data lines ...
;
proc format;
value qf .A = 'Not Home' .R = 'Refused';
run;
proc freq data=surveyf;
format q1 qf.;
tables q1 / missprint;
run;
I merged the two threads concerning the same issue.
Please do not double-post.
Thanks, I will take note.
Lear0010
Can you use .A and .R instead and treat the values as numerics?
DATA survey;
INPUT id q1 : $20.;
if q1='A' then q=.n;
else if q1='R' then q=.r;
else q=input(q1,best.);
CARDS;
8401 2
8402 A
8403 1
8404 1
8405 2
8406 3
8407 A
8408 1
8408 R
8410 2
;
run;
proc format;
value q .n = 'Not Home' .r = 'Refused';
run;
proc freq data=survey;
table q/missprint;
format q q.;
run;
Thanks for your quick responses. I revised the program as suggested by Reeza, Ksharp, and Astounding, and they all worked!
Lear0010
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.