BookmarkSubscribeRSS Feed
vincentgoh88
Fluorite | Level 6

How to solve the question below? 

 

Given the raw data file EMPLOYEE:
----I----1 0---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)

4 REPLIES 4
andreas_lds
Jade | Level 19

@vincentgoh88 wrote:

How to solve the question below? 


By executing the code an reading the created dataset.

Astounding
PROC Star
You are not required to read in every piece of data on each line. SAS assumes that when the INPUT statement is finished, you have read in all the information you want from the current line of data.

So SAS reads in "Ruth" from the first line of data, and the INPUT statement ends. SAS assumes that you have read everything you need from line 1. The next INPUT statement reads IDNUM from line 2, columns 10-11.
ballardw
Super User

Be aware that text posted into the main message windows may not actually reflect what you intended if you used a copy/paste.

 

123 789

   123   789  

The text was copied from the SAS Editor and pasted above. The first bit the leading blanks and 2 blanks between 3 and 7 were removed by the formum software. The second bit was pasted into a code box opened with the forum's {I} icon.

 

Why do I mention that? We cannot actually be sure that the data step we see was the actual data step that should be considered for answering questions. And you specific question answer would change drastically depending on the number and position of blanks.

 

Another obnoxious bit is that the data step code you pasted will not actually run.

data test;
infile employee;
input employee_name $ 1-4;
if employee_name = Ruth then input idnum 10-11;
else input age 7-8;
run;

The quotes shown that are angled will generate errors such as:

6    if employee_name = ‘Ruth’ then input idnum 10-11;
                        -
                        390
                        76
ERROR 390-185: Expecting an relational or arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

because the characters the SAS compiler expects for quotes are either ' or "

 

Ksharp
Super User

It should be 22.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 677 views
  • 0 likes
  • 5 in conversation