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

Hi all,

I'm writing a Java client to accept an SAS expression , validate it and passed it to the backend SAS macro as the if expression in SAS language.  The entered expression will be used as 'if expression' .  I want to validate the syntax  before pass it to the backend. Is there any approach to syntax check it ?   It seems that it's not easy to syntax check it with regular expression as the  if expression in SAS language may be very complicated.

If we want to check the syntax of a where clause in SAS language, SAS/FSP data modeler and SCL could be used.   Is there a similar approach for the if expression?


Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

I am assuming you are talking about a sub-setting IF statement, not any other type?

What about taking a different approach and submit your IF statement to SAS using SYNTAXCHECK mode and/or ERRORABEND to see if it will work OK? You would need to put the IF statement in a DATA step first but you may end up with a more reliable solution as it will pick up other types of errors apart from syntax ones.

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Why not use the WHERE clause syntax check?

What you want to test is the expression. In general anything allowed in a WHERE statement is allowed in an IF statement.

VictorJiang
SAS Employee

Yes, it's a solution. However, it's not the best one.

For example, the 'like' operator is legal in where statement but is illegal in an IF statement.

SASKiwi
PROC Star

I am assuming you are talking about a sub-setting IF statement, not any other type?

What about taking a different approach and submit your IF statement to SAS using SYNTAXCHECK mode and/or ERRORABEND to see if it will work OK? You would need to put the IF statement in a DATA step first but you may end up with a more reliable solution as it will pick up other types of errors apart from syntax ones.

VictorJiang
SAS Employee


Great idea. Yes, I want to check only the syntax of if-then statements. It's a subset of SAS language.

I will put the if-then statement inot a DATA step step first and then submit it to SAS workspace server and check the returned log.  Error will be thronw in the log if there is syntax error.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1852 views
  • 1 like
  • 3 in conversation