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.
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.;
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.;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.