DATA Step, Macro, Functions and more

Reading raw files

Posts: 31

Reading raw files

Why and how does this code proceed?

The contents of the raw data file EMPLOYEE are listed below:
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;
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

Respected Advisor
Posts: 3,124

Re: Reading raw files

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'.


Posts: 31

Re: Reading raw files

Could you please explain what happens here as there is no @, and hence it would move to the next line. But how does it pick the value 40 then?
Please elaborate this processing a bit. Thanks in advance Smiley Happy
Respected Advisor
Posts: 3,124

Re: Reading raw files

'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'.


Ask a Question
Discussion stats
  • 3 replies
  • 1 like
  • 2 in conversation