BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

Hi,

I want to get all the observations where first name starts with Ro, Ay, Su OR Last name starts with Che, Ro.

I know it's possible to code with Where, IF etc, but can someone help with the coding with Perl, please.  Thanks.

 

 

data have;
infile datalines;
input id First_name$8. Last_name&$8.;
datalines;
101 Roy     Rose
102 Yao 	Chen
103 Sushan  Hash
104 Robin   Blue
105 Susan   Robert
106 Susan   Jane
107 Ayesha  Hasan
;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
infile datalines;
input id First_name$8. Last_name&$8.;
datalines;
101 Roy     Rose
102 Yao 	Chen
103 Sushan  Hash
104 Robin   Blue
105 Susan   Robert
106 Susan   Jane
107 Ayesha  Hasan
;
run;

data want;
 set have;
 where prxmatch('/^(Ro|Ay|Su).*/i',First_name) or
 prxmatch('/^(Che|Ro).*/i',Last_name);
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data have;
infile datalines;
input id First_name$8. Last_name&$8.;
datalines;
101 Roy     Rose
102 Yao 	Chen
103 Sushan  Hash
104 Robin   Blue
105 Susan   Robert
106 Susan   Jane
107 Ayesha  Hasan
;
run;

data want;
 set have;
 where prxmatch('/^(Ro|Ay|Su).*/i',First_name) or
 prxmatch('/^(Che|Ro).*/i',Last_name);
run;
novinosrin
Tourmaline | Level 20

I believe most Stalwarts would still think the following is better, faster and convenient

 


data have;
infile datalines;
input id First_name$8. Last_name&$8.;
datalines;
101 Roy     Rose
102 Yao 	Chen
103 Sushan  Hash
104 Robin   Blue
105 Susan   Robert
106 Susan   Jane
107 Ayesha  Hasan
;
run;

data want;
 set have;
 where First_name in :('Ro','Ay','Su') or
 last_name in  :('Che','Ro'); 
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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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