DATA Step, Macro, Functions and more

Make new file based on a Text string

Accepted Solution Solved
Reply
Super Contributor
Posts: 406
Accepted Solution

Make new file based on a Text string

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;

 


Accepted Solutions
Solution
‎02-16-2017 05:01 PM
Frequent Contributor
Posts: 75

Re: Make new file based on a Text string

You can use 'contains' in a where statement:

 

data have2;

set have;

where name contains 'abc1';

run;

View solution in original post


All Replies
Solution
‎02-16-2017 05:01 PM
Frequent Contributor
Posts: 75

Re: Make new file based on a Text string

You can use 'contains' in a where statement:

 

data have2;

set have;

where name contains 'abc1';

run;

Trusted Advisor
Posts: 1,558

Re: Make new file based on a Text string

Posted in reply to nehalsanghvi

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

Super Contributor
Posts: 406

Re: Make new file based on a Text string

Thanks a lot for your suggestions.
HHC
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 137 views
  • 3 likes
  • 3 in conversation