BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

 

I tried below code to convert the words to space if the string ends in limited,ltd,plc,sa,inc. But the third record(limited abc) , the abc is converted to a space. Any help is appreciated!

 

 

data test;
input string $1-12;
cards;
abc limited
pqr ltd
limited abc
abc sa
abc plc 
plc abc
abc inc
;
run;
data want;
 set Test;
 if prxmatch("/(^.*\binc\b|^.*\blimited\b|^.*\bltd\b|^.*\bsa\b|^.*\bplc\b)/i",string) > 0 then do;
 want=prxchange('s/\w+$//',-1,strip(string));
 End;
run;
1 REPLY 1
PGStats
Opal | Level 21

Keep it simple:

 

data have;
input string $12.;
cards;
abc limited
pqr ltd
limited abc
abc sa
abc plc 
plc abc
abc inc
;

data want;
 set have;
 want = prxchange("s/\s*\b(inc|limited|ltd|sa|plc)\s*$//io", 1, string);
run;
PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 525 views
  • 0 likes
  • 2 in conversation