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.
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
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;
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
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!
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.