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!
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.
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.
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.
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.
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.