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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

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