Write and run SAS programs in your web browser

SAS MANIPULATING MISSING DATA

Reply
New Contributor
Posts: 3

SAS MANIPULATING MISSING DATA

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. 

Regular Contributor
Posts: 226

Re: SAS MANIPULATING MISSING DATA

Hi, there are many ways to do this.
Such as using if/else statement, proc format or ifn.
HTH.
Contributor
Posts: 46

Re: SAS MANIPULATING MISSING DATA

[ Edited ]
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

New Contributor
Posts: 3

Re: SAS MANIPULATING MISSING DATA

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 

Regular Contributor
Posts: 226

Re: SAS MANIPULATING MISSING DATA

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=.;
New Contributor
Posts: 3

Re: SAS MANIPULATING MISSING DATA

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.  
Regular Contributor
Posts: 226

Re: SAS MANIPULATING MISSING DATA

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;
Contributor
Posts: 46

Re: SAS MANIPULATING MISSING DATA

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.

 

 

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