BookmarkSubscribeRSS Feed
SASAna
Quartz | Level 8

Hi SAS Users,

 

I need help with finding multiple like values of proc_Cd's. I tried prxmatch(proc_cd , &procs ) > 0 .It didn twork.

 

proc_Cd's are coming in data like -  ( Ex: 1234|2345|7898)

 

procs are coming like  - Ex:  1234,2345,4567,8903

 

proc sql;

create table test as 

select * from test

where proc_cd like (&procs)

;

Quit;

 

Thanks,

Ana

 

6 REPLIES 6
Tom
Super User Tom
Super User

LIKE operator does not support multiple values.  Use the IN operator instead. (Code simplification hint: the IN operator in SAS does NOT need commas between the values. Spaces will do just fine.)

%let procs=1234 2345 4567 8903;
proc sql;
create table test as 
  select * from test
  where proc_cd  in (&procs)
;
quit;
SASAna
Quartz | Level 8
I have multiple values in proc_cd field, which i need to check from the comma delimited procs. I tried this prxmatch(proc_cd , &procs ) > 0 , but it didnt work.
SASAna
Quartz | Level 8

I tried this below small example with hard coded manual entry values , it worked fine. But when i pass the variable names i am getting warning and 0 observations.

 

Works -

 

proc sql;
create table total as
select * from test b
where prxmatch("!(1234|2348)!i" , '1234' ,'2346') > 0
;
Quit;

 

 

Does not work -

 

proc sql;
create table total as
select * from test b
where prxmatch("!(proc_cd)!i" , &proc) > 0
;
Quit;

 

 WARNING: Function PRXMATCH requires at most 2 argument(s). The extra one(s) will be ignored.

 

 

Ksharp
Super User
%let procs=1234|2345|4567|8903;
data want;
set test;
if findw(symget('procs') ,strip(proc_cd),'|') ;
run;;
Ksharp
Super User
procs are coming like - Ex: 1234,2345,4567,8903


proc sql;
create table test as
select * from test
where findw("&procs",strip(proc_cd), ',' );
;
Quit;
mharding
SAS Employee

Hi SASAna,

The below program looks for the values  1234,2345,4567,8903 in the column Code.  The first Data Step creates the test data set.

Let me know if I have misunderstood your question.  

Thanks

Mary

 

data new;
input code $;
datalines;
1234
2345
4567
5464
8903
2090
1234
1234
;
run;
%let procs=1234,2345,4567,8903;

 

data find;
 set new;
 do i= 1 to 4;
   if code=trim(scan("&procs",i,',')) then output;
 end;
run;

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 2135 views
  • 0 likes
  • 4 in conversation