BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathiskumar_D
Obsidian | Level 7
---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”? 
 
 
I have no clue how to deduct the answer.Please help me with reason.Answer for this question is appreciated.However, I need an explanation.thanks in advance.
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Run the step first. Then apply your knowledge about "data step concepts" (if this is not yet present, get it through googling for the phrase and study the respective SAS documentation) to the result, and you will arrive at the answer.

The intent of such exercises is that you find the answer (and thus hone your skills), not somebody else.

View solution in original post

9 REPLIES 9
Kurt_Bremser
Super User

Run the step first. Then apply your knowledge about "data step concepts" (if this is not yet present, get it through googling for the phrase and study the respective SAS documentation) to the result, and you will arrive at the answer.

The intent of such exercises is that you find the answer (and thus hone your skills), not somebody else.

Ksharp
Super User

Since you didn't add @ at the end of "input employee_name $ 1-4; ".

that means point will go to the next row.

it should be 22 .

Sathiskumar_D
Obsidian | Level 7
Thanks Mr.Ksharp. I am still novice to SAS and still in the learning curve.I couldn't run this program in SAS studio.I tried it.It showing the syntax error.That's why i posted in this forum.Will read the basics again.
Cynthia_sas
SAS Super FREQ

Hi:

  To test the program, you either would have needed to make a file called "employee" and type the datalines into the file or modify the program slightly to use the INFILE DATALINES technique for reading in test data. Here's an example of using INFILE DATALINES:

data test; 
  infile datalines; 
  input employee_name $ 1-4; 
  if employee_name = 'Ruth' then input idnum 10-11; 
  else input age 7-8; 
datalines;
Ruth  39 11 
Jose  32 22 
Sue   30 33 
John  40 44 
; 
run; 
proc print data=test;
  title '1) After running original program';
run;

  We do show this technique in our Programming 1 class and the technique of using DATALINES to provide a program with "instream" data is well documented.

 

  Then, once you run the program and see that KSharp was correct, that the value would be 22 -- as shown below:

input_statement_behavior.png

--then you can read about using the single trailing @ sign to modify the behavior of the INPUT statement.

 

  Every time an INPUT statement is encountered in a program, (EVERY time), a new row or new dataline is loaded into the INPUT buffer area. So without any other controls in place, SAS will go to a new dataline after reading the name on the first row.

 

Cynthia

Sathiskumar_D
Obsidian | Level 7

Thanks  a lot for showing the program in detail .I did something when writing this program in SAS studio.I'll fix it and run.

art297
Opal | Level 21

I agree with @Kurt_Bremser that you really should first experiement and see if you can answer the questions yourself.

 

If there really are blank lines between each record, the code won't even run. And, if there aren't blank lines between each record, and the data are exactly the way you entered them, then the answer is 2 as SAS will try to read two digits beginning in column 10, but only one digit exists there.

 

Art, CEO, AnalystFinder.com

 

Cynthia_sas
SAS Super FREQ
Hi:
If this is an interview or homework question, then you have everything you need to run the program and test it to understand how the INFILE statement works when coded as you show.

cynthia
napatel0911
Calcite | Level 5

ans is 22. because when you put input statement again after then.. then it will take value of next variable.(as per my knowledge)

ballardw
Super User

It is a very good idea to post code and example data using codeboxes opened with the forum {i} menu icon.

As posted your code won't produce very similar results as the forum window has likely inserted additional blank lines.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 9 replies
  • 4037 views
  • 7 likes
  • 7 in conversation