BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pchen002
Obsidian | Level 7

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”?

 

Ans is 22? I do not understand why. Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Having the code: "INPUT IDNUM 10-11;" means get idnum from positions 10-11.

 

Having "INPUT NAME 1-4 @";   you stay on current row with name=RUTH.

Without the @ character, sas skips to the next row where name=JOSE then

reads positions 10-11 with idnum=22;

View solution in original post

7 REPLIES 7
Reeza
Super User

 No trailing @. 

Each INPUT statement reads from a new line by default. To keep it on the same line you need the trailing @. 

pchen002
Obsidian | Level 7

Sorry I still don't quite get it, still a noobie for SAS!!

Shmuel
Garnet | Level 18

Compare next code to the one you used:

 

data test;
infile ‘employee’;
input employee_name $ 1-4  @;    /* <<<< @ added <<< */
if employee_name = ‘Ruth’ then input idnum 10-11;
else input age 7-8;
run;

You got 22 taken from next row.

The @ character makes sas stay on current row up to next INPUT ...; staement (without @).

pchen002
Obsidian | Level 7
I understand the @ part already, but where do they start reading the data for idnum 10-11(not sure which column they read to result the observation=22)?
Shmuel
Garnet | Level 18

Having the code: "INPUT IDNUM 10-11;" means get idnum from positions 10-11.

 

Having "INPUT NAME 1-4 @";   you stay on current row with name=RUTH.

Without the @ character, sas skips to the next row where name=JOSE then

reads positions 10-11 with idnum=22;

pchen002
Obsidian | Level 7
Understood!thanks!!
error_prone
Barite | Level 11
SAS reads from the columns you specified in
"then input idnum 10-11;"

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
  • 7 replies
  • 1354 views
  • 1 like
  • 4 in conversation