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

Hi Guys,

 

Can you please explain me why the data set test created is having Ruth idnum as 22 rather than 11 and Suey age as 40 rather than 30. This has been asked in certification exam, so I need the clarity for the answer. Following is the program:

 

 

data test;
infile cards;
input employee_name $ 1-4;
if employee_name = 'Ruth' then input idnum 9-10;
else input age 6-7;
cards;
Ruth 39 11
Jose 32 22
Suey 30 33
John 40 44
;
run;

 

Dataset created is :

 

employee_name    idnum    age

Ruth                             22         .

Suey                               .       40

 

 

Thanks in Advance 🙂

Ayushmaan

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Because after executing every INPUT statement ,the pointer is going to next row.

So after first input, the pointer jump into the next row,and input idnum 9-10; will input 22 ,not 11.

if you want input 11, add @    at the end of INPUT to avoid it to jump into next row.

 

 

data test;
infile cards;
input employee_name $ 1-4 @;
if employee_name = 'Ruth' then input idnum 9-10 ;
else input age 6-7;
cards;
Ruth 39 11
Jose 32 22
Suey 30 33
John 40 44
;
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

The first input reads positions 1-4 on line 1, and skips to line 2. The second (conditional) input reads pos. 9-10 on line 2.

The observation is written, the data step iterates, reads pos. 1-4 on line 3 and skips to line4, where pos. 6-7 are read as age.

You probably wanted to hold the input line:

data test;
infile cards missover;
input employee_name $ 1-4@;
if employee_name = 'Ruth' then input idnum 9-10;
else input age 6-7;
cards;
Ruth 39 11
Jose 32 22
Suey 30 33
John 40 44
;
run;

 

Ksharp
Super User

Because after executing every INPUT statement ,the pointer is going to next row.

So after first input, the pointer jump into the next row,and input idnum 9-10; will input 22 ,not 11.

if you want input 11, add @    at the end of INPUT to avoid it to jump into next row.

 

 

data test;
infile cards;
input employee_name $ 1-4 @;
if employee_name = 'Ruth' then input idnum 9-10 ;
else input age 6-7;
cards;
Ruth 39 11
Jose 32 22
Suey 30 33
John 40 44
;
run;
ab12nov
Obsidian | Level 7
Thanks...!!! 🙂

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
  • 843 views
  • 3 likes
  • 3 in conversation