BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bobbyfajardo
Fluorite | Level 6

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
PetriRoine
Pyrite | Level 9

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 year from ACAD_TERM_DESC:
    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

View solution in original post

7 REPLIES 7
ballardw
Super User

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.

Sam_SAS
SAS Employee
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
bobbyfajardo
Fluorite | Level 6

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. 

bobbyfajardo
Fluorite | Level 6

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

Sam_SAS
SAS Employee

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

PetriRoine
Pyrite | Level 9

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 year from ACAD_TERM_DESC:
    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

bobbyfajardo
Fluorite | Level 6

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(
'ACAD_TERM_YR_SIMS'n, 'COMMA32.'))

 

Much appreciated everyone!

 

Best, Rob

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1156 views
  • 4 likes
  • 4 in conversation