Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concatenating a numeric with character

Tags:

sas

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?

like image 256
athresh Avatar asked Dec 27 '22 11:12

athresh


1 Answers

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

like image 82
Joe Avatar answered Jan 08 '23 21:01

Joe