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';

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 8771 views
  • 15 likes
  • 4 in conversation