Reputation: 11
Given the raw data file EMPLOYEE:
----I----10---I----20---I----30
Ruth 39 11
Jose 32 22
Sue 30 33
John 40 44
The following SAS program is submitted:
data test;
infile 'employee';
input employee_name $ 1-4;
if employee_name = 'Ruth' then input idnum 10-11;
else input age 7-8;
run;
What value does the variable IDNUM contain when the name of the employee is “Ruth”?
A. 11
B. 22
C. 33
D. (missing numeric value)
The answer is supposedly 22 (B). Can someone please explain as to why the value of IDNUM would be 22 as opposed to 11? I don't understand how the conditional statement skips over the 11 value for Ruth and goes on to 22, which is the value for Jose.
Upvotes: 0
Views: 473
Reputation: 21264
The answer is 22 because as soon as SAS reads a line it moves on to the next line of data. So when the second input statement is called, it reads the next line, not the current line.
To remain at the same line, you need @ or @@ depending on the functionality you're looking for, and this is documented in the INPUT statement here.
@ holds the line for the current data step, it resets at the RUN statement. @@ holds the line across the RUN statement for multiple iterations.
Upvotes: 3