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?
Try this:
if actual=:'US' then desired=substr(actual,3);
else desired=actual;
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.