Here's a SAS BASE certification exam sample question:
The following SAS program is submitted:
data work.flights;
destination = 'CPH';
select(destination);
when('LHR') city = 'London';
when('CPH') city ='Copenhagen';
otherwise;
end;
run;
Which of the following is the value of the CITY variable?
A. London
B. Copenh
C. Copenhagen
D. ' ' (missing char value)
why is the answer B not C? also, within the Select statement, what is the function of 'otherwise'?
Thank you!
nvm... it's because variable CITY took the length of the first instance of the variable, which is 'London'
nvm... it's because variable CITY took the length of the first instance of the variable, which is 'London'
The length of new variable "city" was set by "London". using "otherwise" because destination may have values other than "LHR" and "CPH".
try adding a length statement:
data work.flights;
length city $ 10;
destination = 'CPH';
select(destination);
when('LHR') city = 'London';
when('CPH') city ='Copenhagen';
otherwise;
end;
run;
Otherwise is where it branches when none of the other conditions are met. In this case it does nothing. You can cause run-time errors if you forget to include the otherwise category and your actual data fails to match one of the other conditions. Example:
ERROR: Unsatisfied WHEN clause and no OTHERWISE clause at line 110 column 3.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.