Solved
New Contributor
Posts: 4

# To create a frequency distribution table

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

 The FREQ Procedure
q1 Frequency Percent Cumulative
Frequency Cumulative
Percent
 1 3 30 3 30 2 3 30 6 60 3 1 10 7 70 Not Home 2 20 9 90 Refused 1 10 10 100

Accepted Solutions
Solution
‎09-23-2017 05:04 PM
Super User
Posts: 23,688

## Re: To create a frequency distribution table

Can you use .A and .R instead and treat the values as numerics?

All Replies
Solution
‎09-23-2017 05:04 PM
Super User
Posts: 23,688

## Re: To create a frequency distribution table

Can you use .A and .R instead and treat the values as numerics?

Super User
Posts: 10,770

## Re: To create a frequency distribution table

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;

New Contributor
Posts: 4

## Creating a frequency distribution table

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

 The FREQ Procedure
q1 Frequency Percent Cumulative
Frequency Cumulative
Percent
 1 3 30 3 30 2 3 30 6 60 3 1 10 7 70 Not Home 2 20 9 90 Refused 1 10 10 100

Super User
Posts: 6,756

## Re: Creating a frequency distribution table

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;

Super User
Posts: 10,217

## Re: Creating a frequency distribution table

I merged the two threads concerning the same issue.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 4

## Re: Creating a frequency distribution table

Thanks, I will take note.

Lear0010

New Contributor
Posts: 4

## Re: To create a frequency distribution table

Thanks for your quick responses.  I revised the program as suggested by Reeza, Ksharp, and Astounding, and they all worked!

Lear0010

☑ This topic is solved.