BookmarkSubscribeRSS Feed
spanky4_3
Calcite | Level 5

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.

3 REPLIES 3
art297
Opal | Level 21

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

DLing
Obsidian | Level 7

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;

Peter_C
Rhodochrosite | Level 12

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1551 views
  • 0 likes
  • 4 in conversation