BookmarkSubscribeRSS Feed
kiranch
Obsidian | Level 7

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

7 REPLIES 7
Kurt_Bremser
Super User

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?

Kurt_Bremser
Super User

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)

kiranch
Obsidian | Level 7
Hi Kurtbremser,

Thanks for the response,

Yes, Calendar year in numeric and current_status is Character, I have combinations in my dataset, I am getting the second condition result because If use the termination type I get one result and If I use Current status I get another result.


Thanks,
Kiran
Tom
Super User Tom
Super User

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;
kiranch
Obsidian | Level 7

Thanks Tom, For the immediate response In Sas Visual Analytics, We will create the calculated columns, Check the below Image, You can recollect. 

kiranch_0-1600348608608.png

 

Sam_SAS
SAS Employee

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

 

kiranch
Obsidian | Level 7

Thanks Sam,

 

I will try based on your suggestions.

 

Regards,

Kiran

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

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.

Discussion stats
  • 7 replies
  • 2262 views
  • 0 likes
  • 4 in conversation