BookmarkSubscribeRSS Feed
najiah
Calcite | Level 5

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

3 REPLIES 3
Astounding
PROC Star

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;

najiah
Calcite | Level 5

thank you for your help, It works!

Tom
Super User Tom
Super User

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1008 views
  • 2 likes
  • 3 in conversation