BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

Hi,

 

I want to take all records from the below file out where name variable as a certain phrase like "abc1". 

In the file the new file will contain record 2 and 3 in the file below.

 

Thank you so much.

 

HHC

 

 

Data have;
input name $ 20.;
datalines;
cost_ab
value_abc1
textabc12_x
testabc
; run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
nehalsanghvi
Pyrite | Level 9

You can use 'contains' in a where statement:

 

data have2;

set have;

where name contains 'abc1';

run;

View solution in original post

3 REPLIES 3
nehalsanghvi
Pyrite | Level 9

You can use 'contains' in a where statement:

 

data have2;

set have;

where name contains 'abc1';

run;

Shmuel
Garnet | Level 18

You can use either function contains, as proposed by @nehalsanghvi

or if index(name,'abc1') > 0

 

in case you are looking for digits in name you can use:

if indexc(name,'012345678') > 0

hhchenfx
Barite | Level 11
Thanks a lot for your suggestions.
HHC

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 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
  • 3 replies
  • 865 views
  • 3 likes
  • 3 in conversation