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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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