BookmarkSubscribeRSS Feed
Incubu
Calcite | Level 5

Hello

 

For a sas/af application where the user can put free text related to variable values in a dataset, in order to make a sub-query in a WHERE statement, such as:

SEX=1 AND AGE>=16

 

I need to put quotes in the alphanumeric variable values and leave the numeric ones as they are. Lets say SEX is alphanumeric and AGE numeric, so the result should be:

SEX='1' AND AGE>=16

 

Of course there is a list of alphanumeric and numeric variables and all operators could be used ( = EQ,^= NE,¬= NE,~= NE,> GT,< LT,>= GE,<= LE, IN,& AND,| OR,! OR,¦ OR,¬ NOT,ˆ NOT,~ NOT).

 

Thanks in advance!

3 REPLIES 3
Kurt_Bremser
Super User

So you want users to put in text that is later used in code? Ever heard of "code injection"? I don't want to be in your shoes when you have to explain to the auditors why the data warehouse needs to be rebuilt.

 

PS see https://xkcd.com/327/ 

Incubu
Calcite | Level 5
Thanks for the reply!
This application is restricted for internal users and code is audited before inserted in the query. Only code as described admited.
Kurt_Bremser
Super User

If you audit the code anyway (which is a tedious process), you don't need that fancy stuff. Have users send you the code per email and run it. And if they are able to write that code, have them run it with their own account, which you can restrict appropriately so they don't cause havoc.

 

 

 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 969 views
  • 2 likes
  • 2 in conversation