DATA Step, Macro, Functions and more

Reading raw files

Reply
Occasional Contributor
Posts: 12

Reading raw files

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 

SAS Super FREQ
Posts: 9,424

Re: Reading raw files

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
Super User
Posts: 6,921

Re: Reading raw files

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?

Super User
Posts: 13,913

Re: Reading raw files

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.

Super User
Super User
Posts: 8,267

Re: Reading raw files

Perhaps you are reading past the end of the line?

Try adding the TRUNCOVER option to your INFILE statement.

Ask a Question
Discussion stats
  • 4 replies
  • 71 views
  • 0 likes
  • 5 in conversation