data test;
name = 'abcdefgh';
age = 30;
res = name || age;
run;
When I run the above code the variable res holds -> abcdefgh 30
Why the numeric variable age is padding with blanks and then concatenated with the character variable?
When a number and a character are concatenated, the number is converted to a character variable first, then the two character variables are concatenated together. The default format for converting a numeric variable to a character variable is BEST12. (although that can vary based on the format of your numeric variable). put(30,BEST12.)
would yield ' 30'
which is then concatenated to the character variable.
To avoid this, either use strip as Aaron notes, or do your concatenation using CATS (res=cats(name,age);
) which automatically strips all variables, or put the numeric variable yourself (and with PUT, you can forcibly left-justify it if you want with the -l option).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With