I have a code similiar to this
the macro variable has Value '%678900','%625890','%827189'
proc sql ;
create table as sec;
select * from table1
where var like any (&Value) ;
quit;
It throws an error ERROR: FUNCTION ANY COULD NOT BE LOCATED. Before to escape using like any I used PRXMATCH('~DENIED|INVALID~i',UPPER(DESC)). How to use with macro in proc sql statement?
AFAIK there is no equivalent LIKE list in SAS SQL. However if you could describe the variable you are selecting on in more detail. For example, does it always contain the same number of characters? If so then you could use the SUBSTR function to choose just the last six characters of the string to compare.
The 2 or third character is a "-" after which is numbers which are stored in the macro. If possible how can I save the values in a macro and how do I use it?. I am saving the values in macro by
PROC SQL NOPRINT;
SELECT quote(cats('%',value),"'")
INTO :value separated by ", "
FROM IDS_CODE
;
QUIT;
Maybe something like this will work then:
proc sql ;
create table as sec;
select * from table1
where scan(var,2,'-') in ('123456','789012') ;
quit;
Like this?
proc sql noprint;
select VALUE into :values separated by "|"
from IDS_CODE ;
create table SEC as
select * from TABLE1
where prxmatch("/.*-(&values)/",VAR) ;
quit;
If you want to test the last 6 characters in a variable first remove the % from your macro variable.
Then use SUBSTRN() to get the last 6 characters and see if the result is in your new list of values.
%let value='%678900','%625890','%827189';
%let value6 = %sysfunc(transtrn(%superq(value),%str(%%),));
proc sql ;
create table want as
select * from table1
where substrn(var,length(var)-5) like (&Value6)
;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.