Obsidian | Level 7

## Nexted if else statement Issue

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
Super User

## Re: Nexted if else statement Issue

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?

Super User

## Re: Nexted if else statement Issue

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)

Obsidian | Level 7

## Re: Nexted if else statement Issue

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
Super User

## Re: Nexted if else statement Issue

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

## Re: Nexted if else statement Issue

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

SAS Employee

## Re: Nexted if else statement Issue

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

Obsidian | Level 7

## Re: Nexted if else statement Issue

Thanks Sam,

I will try based on your suggestions.

Regards,

Kiran

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