DATA Step, Macro, Functions and more

input variable at differing offset

Reply
New Contributor
Posts: 3

input variable at differing offset

Hi everyone,

I am trying to process a file with records that have a 'header' with fixed layout, and a body with a variable layout. There is information in the fixed header of the offset within the record for a variable I am trying to read. For example, in the header at say position 10 there is a variable which has the offset location for say a customer name. I can read this offset easy enough, but how would I then input into a CUSTOMER variable from this offset? @OFFSET CUSTOMER $10. ?? I haven't tried this but I am doubtful it will work and hope someone else knows how to process files of this kind.

Thanks,

Mark.

PROC Star
Posts: 7,474

input variable at differing offset

Posted in reply to spanky4_3

It will be easier for people to provide some direction if you provided a small example of what one of the files looks like.  It sounds like you only need to parse the header record and then apply it to the other records.

The following thread contains some examples that might be helpful:

http://www.mathkb.com/Uwe/Forum.aspx/sas/26816/Reading-in-a-flat-file-with-dynamic-headers

Frequent Contributor
Posts: 104

input variable at differing offset

Posted in reply to spanky4_3

Something like this should work...

data out;

     infile in;

     if _n_ = 1 then do;

          input @10 offset ;     * read the varying offset;

          retain offset;             * keep this value across observations; 

          drop offset;               * don't include on output dataset;

     end;

     input @offset customer $10. ;     * all subsequent records;

run;

Valued Guide
Posts: 2,177

input variable at differing offset

Posted in reply to spanky4_3

spanky3_3

you suggest ' I haven't tried this but I am doubtful it will work'

don't be doubtful - it does work

but remember to retain the 'OFFSET' variable

peterC

Ask a Question
Discussion stats
  • 3 replies
  • 560 views
  • 0 likes
  • 4 in conversation