Desktop productivity for business analysts and programmers

reading no. of txt file together

Reply
Regular Contributor
Posts: 220

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.

or

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

please guide...

Thanks.

Super User
Posts: 11,107

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,786

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.

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.

Regular Contributor
Posts: 220

Re: reading no. of txt file together

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

Ask a Question
Discussion stats
  • 4 replies
  • 213 views
  • 0 likes
  • 4 in conversation