BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
2 REPLIES 2
ArtC
Rhodochrosite | Level 12
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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