BookmarkSubscribeRSS Feed
sas_9
Obsidian | Level 7

hi all,

can i read no. of txt files together from one directory? all txt has different no. of variables and different no. of raws. however all txt file has 3 variables in common. I want to combine all txt file into one dataset.

or

i have import seperately each and every txt file and then use SET statement to combine?

please guide...

Thanks.

4 REPLIES 4
ballardw
Super User

If the three variables in common are the first three it may be practical, otherwise it is probably going to be easier to read the three files separately.

OS2Rules
Obsidian | Level 7

You didn't mention whether there are other files / different data types in the directory as well as your text files.

In this case I would run a directory listing into a temporary file and read that back into my program as data.  You can parse your text files from this and use a macro to read all the files - then concatenate with PROC APPEND.  When I read the text files I just read the entire line as a single variable and then parse the data I want out from that using substr or scan functions.  Maybe a more involved process, but tried and true.

data_null__
Jade | Level 19

You can use the techniques described in example 2 of this paper to do exactly what you want.  The fields can be in any order or missing.

http://www.lexjansen.com/pharmasug/2011/TT/PharmaSUG-2011-TT04.pdf

I can send you a macrofied version of this program if you are interested.

sas_9
Obsidian | Level 7

@ballardw - fortunately i ahve first 3 variable in common for all .txt file

@ OS2Rule - Thanks for your high level overview

@ data_null - i would really appreciate if i can get Macro regarding same coz i am not that expert at macro at all...

here is the background

this is all about census data sumamry file 1 data @ http://www2.census.gov/census_2010/04-Summary_File_1/. I am collecting data for Delaware state currently.

I have unzip delaware state data and rename all 47 file to .txt file- then saved all 47 .txt file under 'DELAWARE' directory which is stored on desktop.

delaware 'C:\Documents and Settings\xyz\Desktop'             /* delaware contains 47 .txt file) */

/* txt file name like

de0000012010.txt

de0000022010.txt

de0000032010.txt

.

.

.

de00000472010.txt

*/

these are raw data

all 47 .txt file has first 3 obs in common (SF1ST, DE, 000). variable name for all 3 obs mentioned in technical docs online which would be (FILEID=SF1ST, STUSAB=DE, CHARITER=000).

****really appreciate your time...*****;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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