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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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