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

hi everyone,

 

i want to REMOVE the words connect to _ABCD and also _ABCD itself.

 

can anyone tell me how to do? and is it possible not to remove the word before it when it is one string like my example row 4?

 

Name

THE CLIFTON_ABCD
THE FOODIE BA_ABCD
THE HOME UBON_ABCD

MAKRONO_ABCD

thanks you so much for Helping me!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input var $30.;
cards;
THE CLIFTON_ABCD
THE FOODIE BA_ABCD
THE HOME UBON_ABCD
MAKRONO_ABCD 
;

data want;
set have;
length want $50;
if countw(var,' ')>1 then want=substr(var,1,prxmatch('/\b[a-z]+_ABCD\b/i', var)-1);
else want=var;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
data have;
input var $30.;
cards;
THE CLIFTON_ABCD
THE FOODIE BA_ABCD
THE HOME UBON_ABCD
MAKRONO_ABCD 
;

data want;
set have;
length want $50;
if countw(var,' ')>1 then want=substr(var,1,prxmatch('/\b[a-z]+_ABCD\b/i', var)-1);
else want=var;
run;
ed_sas_member
Meteorite | Level 14

Hi @harrylui 

 

Another approach, also using a pearl regular expression:

data have;
	input name $50.;
	cards;
THE CLIFTON_ABCD
THE FOODIE BA_ABCD
THE HOME UBON_ABCD
MAKRONO_ABCD 
;

data want;
	set have;
	length name2 $30;
	name2 = prxchange('s/(.+)\b.+_ABCD/$1/',-1,name);
run;
harrylui
Obsidian | Level 7

thank you

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!

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
  • 3 replies
  • 492 views
  • 1 like
  • 3 in conversation