Help using Base SAS procedures

Reading data from multiple lines

Reply
N/A
Posts: 0

Reading data from multiple lines

Very basic question but could not find on the forums with the search.
I have a dataset that has different information on different lines. How can I read in the info in a "linear" way.
Example:
601 Part# Part Name Code1 Code2
603 Model Info1 Info2 Info3
604 Region Sales1 Sales2
601 Part# Part Name Code1 Code 2
602 Next Level Part
603 Model Info1 Info2 Info3
604
etc.
I want to pick out Part# Part Name Model Region as a single record for processing but there is no common "thread" in each line to tie to. There are also not always lines for each occurence, in this case part numbers.
What have I missed?
Thanks.
Valued Guide
Posts: 632

Re: Reading data from multiple lines

You can approach this more than one way. Using the INPUT statement you will probably want to be familiar with the trailing @ to read part of an input line while holding onto the line itself. Also you may want to use the # which allows you to read multiple input lines.

The key is to read a portion of the input line, hold it with a trailing @ and then use logic to decide how to proceed with that specific line and subsequent lines for that observation.
Super Contributor
Super Contributor
Posts: 3,174

Re: Reading data from multiple lines

Either you will need to have a fixed-format record or declare some delimiter-character that will be used to parse each record to create individual pieces, even as much with your header-row which appears cumbersome to deal with, from your data example. One approach would be to load the input buffer which populates special-named SAS variable _INFILE_ and then use a DO UNTIL(FOREVER); / END; code-paragraph along with SCAN function to assign variables (over compensating for length and type to get the data loaded first in to a SAS file). Then using another special variable _N_ assign an OBSNUM variable to track and re-connnect disjoint field-values, back into some purposeful orientation, possibly using PROC TRANSPOSE I would expect.

Suggest the OP get the individual "component piece" parsing down first, then tackle how to reassemble pieces into usable data-rows, as needed.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 2 replies
  • 237 views
  • 0 likes
  • 3 in conversation