02-14-2018 09:28 AM
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 ?
02-14-2018 09:38 AM
02-14-2018 09:49 AM
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.
02-14-2018 09:58 AM
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 ?
02-14-2018 10:30 AM
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
Never actually used the third option in this, and was surprised myself that there was one.
02-14-2018 11:20 AM
OK, based on your answer, I designed a little test :
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.
02-14-2018 11:36 AM
May help. It is logical that missing is a separate consideration, and should appear as a group before variables with actual data.
Need further help from the community? Please ask a new question.