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

The following SAS program is submitted:

 

 

data numrecords;

 

infile ‘file specification’;

 

input@1 patient $15.

 

relative$ 16-26@;

 

if relative = ‘children’ then

 

input @54 diagnosis $15. @;

 

else if relative = ‘parents’ then

 

input @28 doctor $15.

 

clinic $ 44-53

 

@54 diagnosis $15. @;

 

input age;

 

run;

 

 

in this raw data why only 2 raw data records are read during each iteration of data step execution , it is mentioned input age so it should be 1 raw data record read not two . plz help 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

If this is a quiz or interview question, the answer is 1 raw data record is being read on each iteration of the DATA step execution. Notice how each INPUT statement ends with a trailing @ except for the last INPUT for age, which releases the held data row.

  If you mock up the data based on the program, this is what you get.

numrecords.png



Cynthia

View solution in original post

7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi: Since you don't post a sample of your data, it is hard to guess why the program is working the way it works. Typically, people use a single trailing @ sign because they need to use some information from the beginning of a data row to determine how to read the rest of a data row. Sometimes, the single trailing @ is used to read hierarchical data, where the raw data for one observation spans multiple lines. However, without any data to look at, it is nearly impossible to answer your question.

The bottom line is that every INPUT statement loads a new raw data row to be loaded into the INPUT buffer unless you "hold" the data row with a trailing @.

I find it odd that you are reading every other piece of data with a specific column pointer (@1, @54) or column location (44-53), but you are reading age with no qualifiers. Where is age located (what position) in the INPUT data row?

What error messages in the log are you receiving? Are you sure that the values for the variable RELATIVE are exactly, the string 'children' (all lower case) or the string 'parents' (all lower case)?

Without seeing your data, it is hard to speculate.

Cynthia
spal12
Calcite | Level 5

The following SAS program is submitted:

data numrecords;

infile 'file specification';

input @1 patient $15. 

relative $ 16-26 @;

if relative = 'children' then input @54 diagnosis $15. @;

else if relative = 'parents' then input @ 28 doctor $ 15.

clinic $ 44-53

@54 diagnosis $ 15. @;

input age;

run;

how many raw data records are read during each iteration of the DATA step execution?

A. 1

B. 2

C. 3

D. 4

 

Can anyone please explain what can be the answer and why?

 

Cynthia_sas
SAS Super FREQ

Hi:

If this is a quiz or interview question, the answer is 1 raw data record is being read on each iteration of the DATA step execution. Notice how each INPUT statement ends with a trailing @ except for the last INPUT for age, which releases the held data row.

  If you mock up the data based on the program, this is what you get.

numrecords.png



Cynthia

xinzhou
Calcite | Level 5

I like your answer, you analysed the question carefully to understand what the author tried to achieve.

Astounding
PROC Star

The log often prints messages about what happened.  For example, you might see a message about SAS moving on to a new line when it reached past the end of the current line.

 

Did you read the log?  Do you still have it available to post here?

ballardw
Super User

If the data in the external file is not sensitive then paste it into a code box opened with the forums {I} icon. Text pasted in the main message boxes can get reformatted removing white space such that the result may not actually represent your data.

Tom
Super User Tom
Super User

Perhaps you are reading past the end of the line?

Try adding the TRUNCOVER option to your INFILE statement.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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