DATA Step, Macro, Functions and more

How to detect and Compute the missing value?

Reply
Occasional Contributor
Posts: 7

How to detect and Compute the missing value?

In the data below, the Likert scale should be in the range of 1-4.

Therefore, I would like to recode the answer 5 to '.'

But it did not succeed.

Then, how can I delete the question that consisted of missing value in SAS?

The actual data could be find the attachment (DAT file)

The editor that I wrote:

DATA example;

INFILE 'C:\Users\nadzatul.abdullah\Documents\My SAS Files\9.3\example.dat' DLM = '09'x DSD;

INPUT  Q1 Q2;

MISS =5;

ARRAY vv(2) Q1 Q2;

DO i=1 TO 2;

IF vv(i)=. THEN DO;

MISS=99 ;

i= 2;

END;

END;

RUN;

PROC FREQ;

WHERE miss =5;

TABLES Q1 Q2 ;

RUN ;

PROC PRINT DATA = example;

TITLE 'example';

RUN;

The output looks like this:

Thank you

Attachment
Super User
Posts: 5,084

Re: How to detect and Compute the missing value?

It's not entirely clear what you are trying to achieve, but it will be easy no matter what.  If you really wanted to delete observations, use a DELETE statement.  You don't need values of 5 or 99 to do this:

if q1=. then delete;

if q2=. then delete;

You could always incorporate this into the array logic that you are using now if you have many variables.

If you don't want to delete, but merely want to omit some observations from analysis, you could try a WHERE statement:

proc freq;

   tables q1 q2;

   where n(of q1-q2)=2;

run;

Occasional Contributor
Posts: 7

Re: How to detect and Compute the missing value?

thank you for your help, It works!

Super User
Super User
Posts: 6,500

Re: How to detect and Compute the missing value?

Sounds from the words like you just want to convert the 5's to missing values.  I am not sure what the 99's have to do with it.

For your simple example you just want something like this.

data want ;

infile 'example.dat';

input q1 q2 ;

if q1=5 then q1=.;

if q2=5 then q2=.;

run;

If you want to distinquish the "5" values from the actual missing values then use one of SAS special missing values instead.

data want ;

infile 'example.dat';

input q1 q2 ;

if q1=5 then q1=.M;

if q2=5 then q2=.M;

run;

To see the result use the MISSPRINT option on PROC FREQ.

proc freq ;

tables q1 q2 / missprint;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 245 views
  • 2 likes
  • 3 in conversation