DATA Step, Macro, Functions and more

Skip missing values in a if statement

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

Skip missing values in a if statement

Hi everyone,

 

Here is some sample data:

XY
14.
2.
2.
21
01

 

I would like to create a simple variable "improvement" the code is 

 

if X < Y then improve = 1; 
else improve = 0;

 

How can I get SAS to skip the rows where Y is missing? This is what I want:

 

XYImprove
14.0
2.0
2.0
211
01            0

 

 

Thanks in advance!


Accepted Solutions
Solution
‎08-14-2017 11:09 AM
Contributor
Posts: 55

Re: Skip missing values in a if statement

Doh! I resolved my own post.

if missing(x) then improve =.;

View solution in original post


All Replies
Solution
‎08-14-2017 11:09 AM
Contributor
Posts: 55

Re: Skip missing values in a if statement

Doh! I resolved my own post.

if missing(x) then improve =.;
Contributor
Posts: 33

Re: Skip missing values in a if statement

'skip' as in drop the records or 'skip' as in don't set a value for improve if y is missing?  Or something else?

Super User
Posts: 19,855

Re: Skip missing values in a if statement

Posted in reply to tomrvincent
if X < Y and not missing(Y) then improve = 1; 
else if not missing(Y) then improve = 0;

 Another option for you: 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 89 views
  • 0 likes
  • 3 in conversation