Desktop productivity for business analysts and programmers

reading no. of txt file together

Regular Contributor
Posts: 225

reading no. of txt file together

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.


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

please guide...


Super User
Posts: 13,942

Re: reading no. of txt file together

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.

Super Contributor
Posts: 358

Re: reading no. of txt file together

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.

Respected Advisor
Posts: 3,867

Re: reading no. of txt file together

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.

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

Regular Contributor
Posts: 225

Re: reading no. of txt file together

Posted in reply to data_null__

@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 @ 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









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

Ask a Question
Discussion stats
  • 4 replies
  • 4 in conversation