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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 1364 views
  • 0 likes
  • 4 in conversation