SAS Certified Base Programmer 123 Questions (73)
The following SAS program is submitted:
data work.test; First = 'Ipswich, England'; City_Country= substr(First,1,7)!!', '!!'England'; run;
Which one of the following is the length of the variable CITY_COUNTRY in the output data set?
A. 6
B. 7
C. 17
D. 25
Topics:
SAS Base Questions |
8 Comments »
D
I believe the answer should be 16, which is what I get when I evaluate LENGTH(City_Country). This concatinates 3 strings, the first with length 7, the second with length 2 and the third with length 7, and 7+2+7=16.
Yes i also believed the length to be 16….but when you give proc contents and check for the variable length….it is coming as 25…….though i am also not able to find a explanation as too how 25…!!!
if any one knows the explanation…do plz state it here
The length of First is 16.
The length of ‘ ,’ is 2.
The length of England is 7.
So the length of City_Country is 16+2+7=25.
The Substr function always takes its length from the variable in the argument. So that implies the length from the substr function is 16.
Now the length of ” ,” is 2. And the length of “England” is 7.
The length of the target variable (City_Country) after concatenation is a sum of the lengths of each part. Therefore 16+2+7=25.
I hope that helps.
The ans should be 16.
try this ↓
you can get the value of omg as 16.
data work.hh;
First = ‘Ipswich, England’;
City_Country= substr(First,1,7)!!’, ‘!!’England’;
omg=length(City_country);
run;
proc print data=work.hh;
var City_country omg;
run;
what’s more interesting is if you try hard-code (I counted the numbers of space in SAS Studio)
hardcode=length(‘Ipswich , England’);
It gives 25!
Anyway, the question would be more likely to ask the len column output by the PROC contents.
Well the comment didn’t display properly…… it’s
hardcode=length(‘Ipswich_________, England’);