The following SAS program is submitted:
data work.test;
Author = ‘Agatha Christie’;
First = substr(scan(author,1,’ ,’),1,1);
run;
Which one of the following is the length of the variable FIRST in the output data set?
A. 1
B. 6
C. 15
D. 200
The following SAS program is submitted:
data work.test;
Author = ‘Agatha Christie’;
First = substr(scan(author,1,’ ,’),1,1);
run;
Which one of the following is the length of the variable FIRST in the output data set?
A. 1
B. 6
C. 15
D. 200
C. Length is as Author.
Answer is 15
The answer used to be 200 – in versions of SAS earlier than 9.4, scan would have defaulted to a length of 200 causing the substr to default to 200 as well.
However, the answer in SAS version 9.4 is 15. This is a change in the new version. Scan function now defaults to the length of the string, just as substr does.
I am confident this is correct because I just got this question wrong on the SAS certification practice exam! 🙂 I put 200 and it was incorrect. The explanation it gives is:
“As of SAS 9.4, if the SCAN function returns a value to a variable that has not yet been given a length, that variable is given the length of the first argument”
The answer to this question is “C” which is “15” .
The answer used to be 200 – in versions of SAS earlier than 9.4, scan would have defaulted to a length of 200 causing the substr to default to 200 as well.
“As of SAS 9.4, if the SCAN function returns a value to a variable that has not yet been given a length, that variable is given the length of the first argument”