BookmarkSubscribeRSS Feed
Amy0223
Quartz | Level 8

Hi! I'm a little confused about the question below and not sure how to code it. Any input is greatly appreciated. Thank you!

 

A sas dataset has the following values for its 35 numeric variables:

99 Do not know

98 Refused to answer

97 Skipped question

Write the data step statement to convert these values to the standard sas missing value (.)

5 REPLIES 5
Reeza
Super User

@Amy0223 wrote:

Hi! I'm a little confused about the question below and not sure how to code it. Any input is greatly appreciated. Thank you!

 

A sas dataset has the following values for its 35 numeric variables:

99 Do not know

98 Refused to answer

97 Skipped question

Write the data step statement to convert these values to the standard sas missing value (.)


Here's an example you can run based on the CLASS data set. I prefer to use CALL MISSING to set values to missing because it works the same for numeric and character variables. 

 

Depending on what you've been studying so far, if this is homework, you may need to use the approach taught in class rather than what I've posted.

 

data example;
set sashelp.class;

if age in (12, 13, 14) then call missing(age);



*if age=12 or age=13 or age=14 then age = . ;

run;
Amy0223
Quartz | Level 8
Thank you very much for your kind help! I greatly appreciate it!
Amy0223
Quartz | Level 8

Does this answer look right? I'm not sure what I need to do with 35 numeric variables.

Data zz;
input x response $18.;
cards;
99 Do not know
98 Refused to answer
97 Skipped question
;
run;
proc print;
run;

data zz1;
set zz;
if x in (99, 98, 97) then call missing(x);
run;
proc print;
run;
Tom
Super User Tom
Super User

A good way to do the same thing for more than one variable is to use an array.  Did you learn how to use an array?

Amy0223
Quartz | Level 8
Yes, I'll try this again using array. Thank you so much!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 720 views
  • 0 likes
  • 3 in conversation