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 ?
output=ifn(x ne . and x < 1,1,x);
output=ifn(x ne . and x < 1,1,x);
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.
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 ?
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.
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.