BookmarkSubscribeRSS Feed
Bulleride
Obsidian | Level 7

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

3 REPLIES 3
Haikuo
Onyx | Level 15

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

 

Bulleride
Obsidian | Level 7
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 🙂
Haikuo
Onyx | Level 15

'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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1127 views
  • 1 like
  • 2 in conversation