BookmarkSubscribeRSS Feed
AlexCarey
Calcite | Level 5

Hello SAS Community:

 

I have a dataset with a character variable, I'll call it "char_var".  If I explore one of "char_var"'s observations, the value for "char_var" appears as 'hello', and when I display it with PROC PRINT, it looks just like 'hello' with no trailing or leading blanks.  When I apply the LENGTH function to the "char_var" variable however and assign that result to a variable I named "len", the value of "len" is 10.  Even when I apply the TRIM and STRIP functions, separately each to "char_var", first, before applying the LENGTH function, and assigning the results to separate variables "len_trim", and "len_strip", respectively, the value stored in each of these variables is also 10.

 

I guess there is some kind of non-printing character that is not getting removed? The reason I need to get just the 'printable' characters isolated is because the "char_var" column is supposed to serve as a "foreign key"  for another table (data set), and since I can't reduce the value of the "char_var" down to the length of just the printable characters, which would be 5, I can't match the value correctly with the 'hello' value in the joining table.

 

I tried using the NOTPRINT and INDEX, FIND functions as well to see if I could locate these 'invisible' characters, but I didn't have any success.

 

Any ideas on how I can strip these extra characters from the "char_var" variables' value to reduce its length to 5 (the length of the printable characters)? Or perhaps another strategy to be able to link the tables on this variable, despite the mismatching lengths?

3 REPLIES 3
Astounding
PROC Star
Print the variable using the $hex20. format and you will see what's in there.
ChrisNZ
Tourmaline | Level 20

It's probably not a white space. One way to remove non-printable characters is to use the compress function with the wk or the s modifier.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1775 views
  • 0 likes
  • 4 in conversation