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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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