DATA Step, Macro, Functions and more

syntax check for the if expression in SAS language

Accepted Solution Solved
Reply
SAS Employee
Posts: 3
Accepted Solution

syntax check for the if expression in SAS language

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!


Accepted Solutions
Solution
‎04-12-2012 05:37 AM
Super User
Posts: 3,110

Re: syntax check for the if expression in SAS language

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


All Replies
Super User
Super User
Posts: 6,500

Re: syntax check for the if expression in SAS language

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.

SAS Employee
Posts: 3

Re: syntax check for the if expression in SAS language

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.

Solution
‎04-12-2012 05:37 AM
Super User
Posts: 3,110

Re: syntax check for the if expression in SAS language

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.

SAS Employee
Posts: 3

Re: syntax check for the if expression in SAS language


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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 355 views
  • 1 like
  • 3 in conversation