04-27-2017 09:46 PM
While using substring function, it ignores the trailing blanks , and i need to retain the trailing blanks of the string,
one= "abc ";
this is the output
one two three four
abc c 7 1
04-27-2017 10:01 PM - edited 04-27-2017 10:05 PM
Replace four=length(two) with four=lengthc(two) and you will see that the trailing blanks are kept in variable two.
data b; one= "abc "; two=substr(one, 3); three=lengthc(one); four=lengthc(two); five = cat('"', two, '"'); run; proc print; run;
04-28-2017 02:41 AM
When you put a string into a SAS character variable that is shorter than the defined length of the variable, then it is always padded with blanks (unless you use substr() on the left side).
data test; length x1 $5 x2 $10 x3 $20; x1 = 'AAAAA'; x2 = 'XXXXXXXXXX'; x3 = put(x2,$hex20.); output; x2 = x1; x3 = put(x2,$hex20.); output; run; proc print data=test noobs; run;
x1 x2 x3 AAAAA XXXXXXXXXX 58585858585858585858 AAAAA AAAAA 41414141412020202020