BookmarkSubscribeRSS Feed
fabdi
Fluorite | Level 6

Hello!

 

I am trying to manipulate the dataset in SAS. I'd like to change my numerical values such as 5 to a . (period) to represent the missing data so it won't count.

 

 I am not sure how to go about it. Please help! 

 

I'm new to SAS. 

7 REPLIES 7
Miracle
Barite | Level 11
Hi, there are many ways to do this.
Such as using if/else statement, proc format or ifn.
HTH.
ankit___gupta
Quartz | Level 8
data more_vars_and_people;
input x y z;
cards;
12 5 9
1 5 30
7 5 20
8 2 3
;
run;


DATA more_vars_and_people;
modify more_vars_and_people;
if y=5 then y=.;
run;

This is an example.. 

 

Hope it helps

fabdi
Fluorite | Level 6

Hello!

 

Thank you for the response! 

 

Hm, I tried creating a new data set (new2) and coding that way. I'm not sure what I am doing wrong. 

 

here is my code.... I am trying to recode all the -99 into . so that it does not count as my data and SAS will consitute it as missing. 

q1a = variable 

 

data new2; set new; 

if q1a<0 THEN q1a=.; run; 

 

~ SASbeginner 

Miracle
Barite | Level 11
Hi, did you want to recode q1a=. when q1a=5 and q1a=-99?
if so, the if statement should be: if q1a in (-99,5) then q1a=.;
fabdi
Fluorite | Level 6

Thank you for the response! 

 

I want to recode just -99 to . 

 

This what I am inputting: 

 

data new2; set new;
 if q1a=-99 THEN q1a=.; run;
 
I'm still seeing -99 counted in my data. I'm not sure what the problem is.  
Miracle
Barite | Level 11

Hi, what does the log say?

The sample code below correctly recoded either numeric or character variables to missing from -99.

data test; 
	numeric=-99; 
	char='-99'; 
	if numeric=-99 then numeric=.; 
	if char='-99' then char=''; 
run;
proc print noobs; run;
ankit___gupta
Quartz | Level 8

Hi fabdi,

 

There is nothing worng with the code as such. The only concern i have is the part where u mention.

"q1a = variable ". Can you elaborate on this part.

 

else everthing is correct.

 

Thank You.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 7 replies
  • 1778 views
  • 2 likes
  • 3 in conversation