SAS Certified Base Programmer 123 Questions (76)
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
Topics:
SAS Base Questions |
13 Comments »
D
I’m getting A as the answer to Q76 – could you check please?
scan(author,1,’ ,’) returns Agatha
substr(agatha,1,1) returns A
Length First = 1
Apologies – error in my LENGTH calcs. The length of FIRST is indeed D – 200
@3. geoff davis Thanks for your comments here…Everyone makes mistakes…:-)
I still don’t know why the answer is 200.
Could someone explain for this?
@ 5 Chris, Install SAS, and run the code…..
Got the same mistake as Geoff davis, I think.
By using Length() function, the length is 1.
By using Proc Contents data=test, the length is 200.
200 is the SAS default length for Char functions.
lenghth 200 is the default length for scan function and not for every character function.
I also get different length using PROC CONTENTS and LENGTH(). so which one should be the answer…?
Oh I see. LENGTH() excludes trailing blanks. LENGTHC() gives the same length as the PROC CONTENTS.
length function returns the length of the argument after removing trailing blanks.It does not give the actual lenth.
Leading and blanks in between are counted towards the length.
the length of character target variable is always 200 bytes long