01-23-2013 09:22 AM
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?
01-23-2013 10:14 AM
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.
01-23-2013 10:50 AM
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.
01-23-2013 11:31 AM
@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
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...*****;