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

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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