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

Appericiate if someone of you help me understand the problem with the code below.

 

Code:

else if (index(lowcase(filename),'_copied.csv') or (index(lowcase(filename),'_copied.xlsx') )  and "&function_compont" EQ 'NL' and (scan(lowcase(filename),5,'_') in ('5601','6010','6020')) then do;

Log:

 

else if (index(lowcase(filename),'_copied.csv') or (index(lowcase(filename),'_copied.xlsx') ) and "&function_compont"
108      !  EQ 'NL' and (scan(lowcase(filename),5,'_') in ('5601','6010','6020')) then do;
SYMBOLGEN:  Macro variable FUNCTION_COMPONT resolves to NL
108            else if (index(lowcase(filename),'_copied.csv') or (index(lowcase(filename),'_copied.xlsx') ) and "&function_compont"
108      !  EQ 'NL' and (scan(lowcase(filename),5,'_') in ('5601','6010','6020')) then do;
                                                                                      ____
                                                                                      22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, 
              IN, LE, LT, MAX, MIN, NE, NG, NL, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=. 
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Writing unstructured spaghetti crap like that will always get you in trouble.

I use the expletive on purpose here. If I saw such a line in production code, they would hear my yelling (while dressing down the **** who spit it out) in the CEO's office. Who works about half a mile (as the crow flies) from me.

Just slightly exaggerating.

 

See if this works for you:

else if
  (
    index(lowcase(filename),'_copied.csv') or
    index(lowcase(filename),'_copied.xlsx')
  )  and
  "&function_compont" EQ 'NL' and 
  scan(lowcase(filename),5,'_') in ('5601','6010','6020')
then do;

Of course, I had to make guesses about your logic.

Also make use of the features of the Enhanced Editor, which highlights closing brackets when the cursor is positioned before the opening bracket, and opening brackets if the cursor is positioned after a closing bracket.

 

But this all will only work for you if you make your code readable.

Maxim 12

Maxim 12

Maxim 12

 

View solution in original post

3 REPLIES 3
gamotte
Rhodochrosite | Level 12
Hello,

The first parenthesis is not closed.
I think you should remove the opening parentheis after the "or" :
or index(lowcase(....
Kurt_Bremser
Super User

Writing unstructured spaghetti crap like that will always get you in trouble.

I use the expletive on purpose here. If I saw such a line in production code, they would hear my yelling (while dressing down the **** who spit it out) in the CEO's office. Who works about half a mile (as the crow flies) from me.

Just slightly exaggerating.

 

See if this works for you:

else if
  (
    index(lowcase(filename),'_copied.csv') or
    index(lowcase(filename),'_copied.xlsx')
  )  and
  "&function_compont" EQ 'NL' and 
  scan(lowcase(filename),5,'_') in ('5601','6010','6020')
then do;

Of course, I had to make guesses about your logic.

Also make use of the features of the Enhanced Editor, which highlights closing brackets when the cursor is positioned before the opening bracket, and opening brackets if the cursor is positioned after a closing bracket.

 

But this all will only work for you if you make your code readable.

Maxim 12

Maxim 12

Maxim 12

 

Shmuel
Garnet | Level 18

Here is your code copied from the log:

else if (index(lowcase(filename),'_copied.csv') or 
        (index(lowcase(filename),'_copied.xlsx') ) 
	and "&function_compont" EQ 'NL' and 
	    (scan(lowcase(filename),5,'_') in ('5601','6010','6020')) 
then do;

you miss an open parenthesis on first line - where it is closed on second line. Check is this what you meant. You don't need last pair of parenthesis.

else if ((index(lowcase(filename),'_copied.csv') or 
        (index(lowcase(filename),'_copied.xlsx') ) 
	and "&function_compont" EQ 'NL' and 
	    scan(lowcase(filename),5,'_') in ('5601','6010','6020') 
then do;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1063 views
  • 3 likes
  • 4 in conversation