SAS Certified Base Programmer 123 Questions (55)
The following SAS program is submitted:
data work.flights;
destination = 'CPH';
select(destination);
when('LHR') city = 'London';
when('CPH') city = 'Copenhgen';
otherwise;
end;
run;
Which one of the following is the value of the CITY variable?
A. London
B. Copenh
C. Copenhagen
D. ‘ ‘ (missing character value)
Topics:
SAS Base Questions |
6 Comments »
B
If we include a length statement for city then we can get the full value…
@sowmya: yes, it ll work if we define lenth before select
why is the default length 6 chars only?
First value for city that occured was “London” and had Length $6. Thesewhy ‘Copenhgen’ was cut off to ‘Copenh’.
The culprit is the statement
when(‘LHR’) city = ‘London’;
Without that statement, the program will yield the desirable result. My 2 cents would be the city variable was created when SAS scanned the code first for syntax error thus the length was only six (London is 6-char long).
Morale of the story: could always put longest word first