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