21.The following SAS program is submitted:
data work.AreaCodes;
Phonenumber=3125551212;
Code='('!!substr(Phonenumber,1,3)!!')'; run;
Which one of the following is the value of the variable Code in the output data set?
a. ( 3)
b. (312)
c. 3
d. 312
Correct answer: a
An automatic data conversion is performed whenever a numeric variable is used where SAS expects a character value. The numeric variable is written with the BEST12. format and the resulting character value is right-aligned when the conversion occurs. In this
example, the value of Phonenumber is converted to character and right-aligned before the SUBSTR function is performed. Since there are only 10 digits in the value of
Phonenumber, the right-aligned value begins with two blanks. Therefore the SUBSTR function picks up two blanks and a 3, and uses the BEST12. format to assign that value to Code. Then, the parentheses are concatenated before and after the two blanks and a 3。
提问 为什么会是right-alinged???是BEST12 format自带的结果吗???求大神回复谢谢!