BookmarkSubscribeRSS Feed
mk131190
Obsidian | Level 7

Hello, 

 

I have 1000s of files in the attached format and I want to import them all into SAS. The files include multiple records per person split by "-----------". I want an output that stacks all of the files and in the process separates all the records within each text file.

 Each text file may have a different number of records that require separating. Effectively every field that is followed by a colon is required as the column name and then the resulting figures that come after it will populate the rows  (anything else is not needed in my output).

 

Is there a relatively simple way of doing this? 

 

Regards,

 

Mark

2 REPLIES 2
cau83
Pyrite | Level 9

Have you figured out how to import a single file correctly? 

Then, can you modify the code to import two different files correctly? 

Then, we could help with the looping. Is your issue the looping or the reading in of data and formatting correctly? The former would be relatively easy to help with, the latter more difficult. I'd recommend you first go and read more about how to use a data step with the infile and input statements and take a crack at it.

ballardw
Super User

ith that type of file layout you will need to tell us what the final data set structure should be such as which of those values are expected to be numeric and which character; does the value of your ID: indicate a new record associated with "file number" or do you expect to have an unspecified number of duplicate values of Name, Address, Occupation, DOB and Gender on every single record; does the value in

Number (001) have meaning (you only show one so we don't know if that changes); does the appearance of this bit"

NUMBER (001)
-------------
DATE:             01/01/2001
FIELD1:		      TEST
FIELD2:			  1
FIELD3:	          2
FIELD4:	          3
FIELD5:	          4 

FIELD6:	          5
FIELD7:	          6
FIELD8:	          7
FIELD9:	          TEST
END                                                                             

Indicate that "Field5:" may contain data on more than one row of the file? If so how many rows? Maximum number of characters involved?

 

 

What role does Filenumber play? You don't indicate whether that goes into the file or not

Personally if it were at all possible I would go back to the source of the data and see if this is available in a different format.

 

Please show what you have attempted so far. If not, this is the kind of stuff that gets charged $150+ per hour to write as contract work.

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