## Missing value is not missing after division, inequality and ifn() call

Solved
Occasional Contributor
Posts: 7

# Missing value is not missing after division, inequality and ifn() call

In a data call, I wrote this :

```x=var1/var2;
output = ifn(x<1, 1, x, .);```

The problem is that when var2 is missing, x is missing, but x<1 is read as TRUE and output is 1 instead of missing.

How can I workaround this behaviour ?

Accepted Solutions
Solution
‎02-14-2018 09:37 AM
Super User
Posts: 9,840

## Re: Missing value is not missing after division, inequality and ifn() call

`output=ifn(x ne . and x < 1,1,x);`

All Replies
Solution
‎02-14-2018 09:37 AM
Super User
Posts: 9,840

## Re: Missing value is not missing after division, inequality and ifn() call

`output=ifn(x ne . and x < 1,1,x);`
Occasional Contributor
Posts: 7

## Re: Missing value is not missing after division, inequality and ifn() call

Thanks, it works !

But I wonder, if this implicitly set output to missing, what is the use of the third argument of ifn ?
Super User
Posts: 9,840

## Re: Missing value is not missing after division, inequality and ifn() call

The condition is ifn(<logic>,result when true, result when false, result when missing)

So if you had .,1,2 in you data you might want if =1, if > 1, if missing.  It just allows to cover for all eventualities, as you might not want . if the value is missing, maybe you want to default in 0.

Occasional Contributor
Posts: 7

## Re: Missing value is not missing after division, inequality and ifn() call

Since var1 is missing, x is also missing, and (x<1) is obviously missing too (else how do you know it's <1 ?). Then it seems that the first <logic> argument cannot see missing values. Else why didn't my code work ?

In the official doc, there is no example of third argument use, could you give me one ?

Super User
Posts: 9,840

## Re: Missing value is not missing after division, inequality and ifn() call

No, . is less than 1 and missing.  So sequentially the logic is:

Is x < 1, the answer is true - stop

Is x >=1 - not evaluated

Is x missing - not evaluated

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002604573.htm

Never actually used the third option in this, and was surprised myself that there was one.

Occasional Contributor
Posts: 7

## Re: Missing value is not missing after division, inequality and ifn() call

```DATA x;
y=.;
x1=y>1;
x2=y<1;
x3=y<-991;
x4=y<0;
x5=y>0;
x6=y<=0;
run;```

My problem is more about the way SAS treats inequalities : it seems that missing values are always "less than" anything.

Coming from R, I find this awfuly misleading, thanks for pointing this out.

Super User
Posts: 9,840

## Re: Missing value is not missing after division, inequality and ifn() call

https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000989180.htm

May help.  It is logical that missing is a separate consideration, and should appear as a group before variables with actual data.

☑ This topic is solved.