Hello Everyone,
Created a new calculation based on nested if-else, only else if part working in the below condition. Can please tell me why if the part is not working
IF ( ( 'Calendar Year'n = 2020 ) AND ( 'current_status'n = '1' )
)
RETURN 1
ELSE (
IF ( ( 'Calendar Year'n In (2020) ) OR ( 'Calendar Month'n In (
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) ) OR ( 'terminationtype'n
In (' ') ) )
RETURN 1
ELSE 0 )
Regards,
Kiran
Maxim 3: Know Your Data.
Is Calendar Year of type numeric?
Is current_status of type character?
Do you actually have a combination of numeric 2020 and character '1' in your data?
The outer condition returns a 1, and the second condition returns a 1, so you can't detect which of those was true. And you use
RETURN 1
for the IFs, but a simple
0
in the ELSE. Should that have been
RETURN 0
? (I am not familiar with VA syntax)
What language is that?
In SAS data step the syntax for IF is IF condition THEN statement.
if ( 'Calendar Year'n = 2020 ) AND ( 'current_status'n = '1' ) then RETURN=1;
ELSE IF ( 'Calendar Year'n In (2020) )
OR ( 'Calendar Month'n In (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) )
OR ( 'terminationtype'n In (' ') ) then RETURN=1;
else return=0;
Thanks Tom, For the immediate response In Sas Visual Analytics, We will create the calculated columns, Check the below Image, You can recollect.
Hello Kiran,
There are two conditions that return 1, so it might be helpful for troubleshooting purposes to change one of them to return 2 so we know which result is being returned.
If I am not mistaken, ( 'Calendar Month'n In (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) ) will always be True unless it is missing. This is equivalent to using the NotMissing operator, if that is your intent.
I believe that ( 'terminationtype'n In (' ') ) might also be better expressed using the Missing operator, although it should work as it is.
Looking at the full expression, it seems like it would be difficult for it ever to return 0.
Sam
Thanks Sam,
I will try based on your suggestions.
Regards,
Kiran
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 16. Read more here about why you should contribute and what is in it for you!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.