By admin | September 17, 2009

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)

6 comments | Add One

  1. admin - 09/17/2009 at 9:54 am

    B

  2. sowmya - 12/22/2010 at 4:00 am

    If we include a length statement for city then we can get the full value…

  3. vaishali - 03/2/2012 at 1:17 pm

    @sowmya: yes, it ll work if we define lenth before select

  4. rob roy - 09/3/2012 at 4:24 am

    why is the default length 6 chars only?

  5. Khai Ming - 11/13/2013 at 6:01 pm

    First value for city that occured was “London” and had Length $6. Thesewhy ‘Copenhgen’ was cut off to ‘Copenh’.

  6. Fleevi - 07/9/2014 at 3:38 pm

    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

Leave a Comment

Leave a Reply

Your email address will not be published.