BookmarkSubscribeRSS Feed
Rohit_1990
Calcite | Level 5

Hi all,

 

In the below dataset I have 2 columns c and y with data as follows:

X

34  45 th avenue

South west 34 street

 

Column y 

th avenue

street

 

So using column y I need to look in column x and if the 1stword is th in y and pattern matches in xthen I need to pull

 The preceding digit 

So my final output z would be something like this.

 

Column y 

45 th avenue

street

 

Regards,

Rohit

 

 

2 REPLIES 2
art297
Opal | Level 21

Something like the following should work:

data have (drop=position length);
  informat x y $30.;
  input x & y &;
  if scan(y,1) eq 'th' then do;
    call scan(x, FINDW(x, 'th',' ', 'e')-1, position, length);
    z=substr(x,position);
  end;
  else z=y;
  cards;
34 45 th avenue  th avenue
South west 34 street  street
;

Art, CEO, AnalystFinder.com

ChrisNZ
Tourmaline | Level 20

Why don't you keep the street number in your example?

What do you do if there is no match?

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
  • 2 replies
  • 657 views
  • 0 likes
  • 3 in conversation