I'm trying to remove the leading indent from a variable. None of trim, trimn, strip and compbl functions work.
What is not working here? I appreciate your suggestions.
data test_urb1; set test_urb; ID_strip=strip(Municipality); ID_trim=trim(left(Municipality)); ID_trimn=trimn(left(Municipality)); ID_compbl=compbl(Municipality); run;
1 ACCEPTED SOLUTION
Repeats of the same 3 characters is making me think that your actual data may be DBCS.
And perhaps the KCOMPRESS, KTRIM may be wanted.
21 REPLIES 21 Tourmaline | Level 20Please check the length's of each value of the Municipality variable in test_urb1 vs Id_strip
using length function.
len=lengthn(id_strip) and notice the difference in the lengths. This should give you some idea than deceiving visuals
Ammonite | Level 13Interesting. What shall I do? Take it as a success in using strip function?
Tourmaline | Level 20Nope all values being 12 bytes of length concerns me.
You may try to remove hexadecimal characters and control chars if any using:
X is hexadecimal characters
C is control chars
id_strip=strip(compress(Municipality,' ','xc'));
Super User
Try displaying the variable with a hex format to see what character are there.
Garnet | Level 18Maybe the indent is not a result of blanks.
check the left most character by:
indent = substr(municipality,1,1); put indent $hex2.;
Ammonite | Level 13
Use the data step generator to show what values you actually have:
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat. will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.
Warning: if you are using some double-byte character set this may not help.
Or use the RANK function to see what the first character may be:
X would be the order in the ASCII (or EBCDIC) character set. If the value is not 32 you do not have a blank. Note that Rank will return the Hex number.
I'm not sure if this will work but the second string below starts with a null character that can be entered on some systems using Alt plus the digits 255 and if the box works correctly the second X= should show 160 (the hex equiv of 255).
data example; string = ' abcdef'; x = rank(first(string)); put x=; string = ' abcdef'; x = rank(first(string)); put x=; run;
The functions you tried would not remove the null as they are not blanks, i.e. ASCII 32.