BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SasStatistics
Pyrite | Level 9

Assume I have the following data stored in a SAS table: 

Actual  Desired
US1234 1234
13 13
14567 14567
US3345 3345


What I would like to do is to check each row, if the first two letters are "US" then I would like to remove those letters. If the first two letters are not "US" I want to keep the row as it is. 

Any idea on how to do this?

1 ACCEPTED SOLUTION
3 REPLIES 3
PaigeMiller
Diamond | Level 26

Try this:

 

if actual=:'US' then desired=substr(actual,3);
else desired=actual;
--
Paige Miller
PaigeMiller
Diamond | Level 26

Maybe COMPRESS works with your data as well as the solution I provided, but COMPRESS will do things to your data that you didn't ask for, such as remove US from anywhere in the string (you didn't ask for that, you asked only for beginning of the string) and it will remove U from anywhere and it will remove S from anywhere. Again, this may work fine on your data, but I point this out for anyone else reading along who may have different data.

--
Paige Miller

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
  • 3 replies
  • 286 views
  • 2 likes
  • 2 in conversation