Why and how does this code proceed?
QUESTION
The contents of the raw data file EMPLOYEE are listed below:
----|----10---|----20---|----30
Ruth 39 11
Jose 32 22
Sue 30 33
John 40 44
The following SAS program is submitted:
data test;
in file' employee';
input employee_ name $ 1-4;
if employee_ name = 'Sue' then input age 7-8;
else input idnum 10-11;
run;
Which one of the following values does the variable AGE contain when the name of
the employee is "Sue"?
A. 30
B. 33
C. 40
D. . (missing numeric value)
Ans –C
This one is straightforward, without line holder @, as
input employee_ name $ 1-4 @;
The 'input' statement will move down to the next line of raw data. That is why you get '40'. With '@' in place, you get to stay on the same line, hence to get '30'.
'40' is one line below Sue's line, so
if employee_name = 'Sue' then input age 7-8;
will move down one line, where 'John' sits, to pick up '40'.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.