SAS Certified Base Programmer 50 Questions (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
Topics:
SAS Base Questions |
7 Comments »
A
what happens when SUBSTR is used for numeric value?
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.
Hey I Can understand your logic..But how did u detect that Numeric Value is Written with best12 format…Pls clear that point alone..
Thanks a lot… I was confused with results when applied substr to numeric variables
wow. good one.
Very clear and complete explanation! Thanks admin!!