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

Hi, I have a string that I'm trying to get only a part of.  The format of the original string is like this: '0000 - Stoney Lynn' and I want the function to output 'Stoney Lynn' with no trailing spaces or proceeding spaces.  There is not a standard amount of spaces between the dash: '0000-Stoney Lynn'.  Also sometimes the dash appears to be a longer dash not recognized as '-'.  This is why I think a function looking for characters after any special character may work better and then trim any extra spaces.

 

Heres what I have tried so far: subjectname=trim(compress((substr(subjectid,5)),'-'))

But some of the output comes back with a dash still and the spaces dont trim correctly.

1 ACCEPTED SOLUTION

Accepted Solutions
Kathryn_SAS
SAS Employee

You can use the SCAN function to extract text after a dash. If it is a regular dash, you can use the following:

subjectname=strip(scan(subjectid,2,'-'));

If it is a long dash, you can use the hex representation:

subjectname=strip(scan(subjectid,2,'96'x));

You can look at a variable in hex using a format:

format subjectid $50.;

View solution in original post

1 REPLY 1
Kathryn_SAS
SAS Employee

You can use the SCAN function to extract text after a dash. If it is a regular dash, you can use the following:

subjectname=strip(scan(subjectid,2,'-'));

If it is a long dash, you can use the hex representation:

subjectname=strip(scan(subjectid,2,'96'x));

You can look at a variable in hex using a format:

format subjectid $50.;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 980 views
  • 2 likes
  • 2 in conversation