Fluorite | Level 6

## Adding more than 155 on a deep nested operator

Hello All,

I'm creating a custom calculated date based on 2 criteria. I was able to create the date however I received this error in the EDIT Calculation pop-up. (in Text view)
Error:
"The expression cannot be saved because an operator is nested too deeply. The current depth is 155 and the maximum depth is 100."

Has anyone else received this error?

Best,  Rob

1 ACCEPTED SOLUTION

Accepted Solutions
Pyrite | Level 9

## Re: Adding more than 155 on a deep nested operator

Hello @bobbyfajardo

Looking at your sample code snippet I believe you could completely get rid-off the long conditional IF-THEN logic.

1. Create My Month
Parse month from ACAD_TERM_DESC along these lines:
```IF ( 'My Season'n = 'Fall' )
RETURN 9
ELSE (
IF ( 'My Season'n = 'Wint' )
RETURN 12
ELSE 3 )```
2. Create My Year
`Parse(Substring('ACAD_TERM_DESC'n, 1, 4), 'COMMA5.')`
3. Create My Date
Create a new date variable:
`DateFromMDY('My Month'n, 1, 'My Year'n)`
4. Your original long code can possibly be shortened now to
```IF ( 'STUDENT LIFECYCLE'n In ('Degree Completed') )
RETURN 'My Date'n
ELSE .```

Please try this approach and let me know how it goes.

Best regards,

Petri

7 REPLIES 7
Super User

## Re: Adding more than 155 on a deep nested operator

Show the code.

It sounds like you have way too many If/then/else statements. Widgets often have some limitation that code doesn't to help reduce the likelihood of sub-optimal code.

If your date is text and made with text manipulation you are almost certainly doing this the hard way.

SAS Super FREQ

## Re: Adding more than 155 on a deep nested operator

I am curious about your expression. Would you be willing to share it?

FWIW, I have some expressions that have a *LOT* of IF/ELSEs and ORs, but I have not seen this error.

Thanks,
Sam
Fluorite | Level 6

## Re: Adding more than 155 on a deep nested operator

Correction: Adding more than 100 on a deep nested operator

Thank you for offering to take a look at my calculated column code. The data is currently on the CAS Server.  I would certainly appreciate any assistance on getting this calculated.

I have another option as a back-up. May need to make multiple tabs, but ideally would love to track the lifecycle from any possible beginning to end.

Here's a sample:

IF ( ( 'STUDENT LIFECYCLE STAGE'n In (‘Degree Completed’) ) AND ('ACAD_TERM_DESC'n In ('2010 Fall') ) )
RETURN '1SEP2010'd
ELSE(

IF ( ( 'STUDENT LIFECYCLE STAGE'n In (‘Degree Completed’) ) AND ('ACAD_TERM_DESC'n In ('2011 Fall') ) )
RETURN '1SEP2011'd
ELSE(

I have it down to 126 deep nested operators.

Fluorite | Level 6

## Re: Adding more than 155 on a deep nested operator

If possible I'd like to do this on the CAS Server using one of the following tools.

SAS Data Studio - "Prepare Data"

SAS Studio - "Develop Code"

Do you have any suggestions as to how a I can make this a code I use in either of the following tools on CAS Server?

I'm trying to keep this column creation on one of the above mentioned tools.  This data is real-time.

Thank you, Rob

SAS Super FREQ

## Re: Adding more than 155 on a deep nested operator

Hi Rob,

If you have permissions to update the source data in CAS, then I believe either of those tools should enable you to create the column you want. It may be easier and/or more elegant this way.

Within VA, I believe that you might also be able to work around the issue by creating a calculated item to perform part of the logic, and then either a second calculated item or a custom category that is based on the first one to perform the rest. I can't promise this will work as I do not have a 155-deep expression to test with.

Sam

Pyrite | Level 9

## Re: Adding more than 155 on a deep nested operator

Hello @bobbyfajardo

Looking at your sample code snippet I believe you could completely get rid-off the long conditional IF-THEN logic.

1. Create My Month
Parse month from ACAD_TERM_DESC along these lines:
```IF ( 'My Season'n = 'Fall' )
RETURN 9
ELSE (
IF ( 'My Season'n = 'Wint' )
RETURN 12
ELSE 3 )```
2. Create My Year
`Parse(Substring('ACAD_TERM_DESC'n, 1, 4), 'COMMA5.')`
3. Create My Date
Create a new date variable:
`DateFromMDY('My Month'n, 1, 'My Year'n)`
4. Your original long code can possibly be shortened now to
```IF ( 'STUDENT LIFECYCLE'n In ('Degree Completed') )
RETURN 'My Date'n
ELSE .```

Please try this approach and let me know how it goes.

Best regards,

Petri

Fluorite | Level 6

## Re: Adding more than 155 on a deep nested operator

Petri,

This gave me a great headstart!

I had to make some minor edits.

New Calculated Column

MyDate

DateFromMDY(Parse('Term_Month_Char'n, 'COMMA32.'), 1, Parse(

Much appreciated everyone!

Best, Rob

Discussion stats
• 7 replies
• 551 views
• 4 likes
• 4 in conversation