BookmarkSubscribeRSS Feed
Vk_2
Obsidian | Level 7

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?

6 REPLIES 6
SASKiwi
PROC Star

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.

Vk_2
Obsidian | Level 7

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;
SASKiwi
PROC Star

Maybe something like this will work then:

proc sql ;
create table as sec;
select * from table1 
where scan(var,2,'-') in ('123456','789012') ;
quit;
ChrisNZ
Tourmaline | Level 20

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;

 

 

jdfrost
Calcite | Level 5
This is a simple solution that will work if and only if the values have the same length. In the example, the search parameter is assumed to be in the beginning of the string. DATA EMPLOYEES; LENGTH LASTNAME $9; INPUT @1 LASTNAME; cards; JONES SMITH Doe wesson CRISCO ; run; proc sql number; select lastname from employees where upper(substr(strip(lastname),1,3)) in ('SMI', 'WES', 'BRO', 'DOE'); quit;
Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 1662 views
  • 2 likes
  • 5 in conversation