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

We can use "=:" to determine whether aString starts with 'ABC' like below:

if aString=:'ABC';

But how to determine aString ends with 'ABC'? Is there an existing function or operator for that? Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
 str='jojojoiABC';
 output;
 str='iknmmoabc';
 output;
 str='knhjknl';
 output;
run;

data want;
 set have;
 if prxmatch('/.*abc$/i',strip(str));
run;

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

data have;
 str='jojojoiABC';
 output;
 str='iknmmoabc';
 output;
 str='knhjknl';
 output;
run;

data want;
 set have;
 if prxmatch('/.*abc$/i',strip(str));
run;
Reeza
Super User
REVERSE() everything?

if reverse(aString) =: reverse(ABC)?

jjjch
Obsidian | Level 7
Thank you, Reeza. Your solution also works. I just hope SAS can provide a string function or operator for endswith().
Reeza
Super User
Or if you know it's a design limitation, you can design your processes to be prefix heavy rather than suffix.
novinosrin
Tourmaline | Level 20

data have;
 str='jojojoiABC';
 output;
 str='iknmmoabc';
 output;
 str='knhjknl';
 output;
run;

data want;
 set have;
 if UPCASE(substr(strip(str),length(strip(str))-2))='ABC';
run;
FreelanceReinh
Jade | Level 19

In a WHERE condition you could also use the LIKE operator:

where aString like '%ABC';

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 8358 views
  • 15 likes
  • 4 in conversation