Date: Thu, 8 May 2008 14:01:09 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: Import Many text files into one dataset
Content-Type: text/plain; charset="iso-8859-1"
SInce I know Nat and he wouldnt mind me making some mods to his code Ill piggy back on it:
Data Files ;
Do FileName = 'importFile1.txt' , 'importFile2.txt' , 'importFile3.txt' ; Files2Read = Cats( 'C:\XXX\YYY\ZZZ\' , FileName ) ; Output ;End ;
Data Need ( Drop = FileName Files2Read ) ;
Set Files ;Infile Dummy FileVar = Files2Read End = Done ;
Do While( Not Done ) ;
Input a b c d e ;
Toby Dunn "Don't bail. The best gold is at the bottom of barrels of crap." Randy Pausch "Be prepared. Luck is where preparation meets opportunity." Randy Pausch> Date: Thu, 8 May 2008 08:29:09 -0400> From: Nathaniel.Wooding@DOM.COM> Subject: Re: Import Many text files into one dataset> To: SAS-L@LISTSERV.UGA.EDU> > BIU> > Is the input field layout identical in all of the input data sets?> > If so, I suggest that you use a Data step to read the files and write your> own input statement. If you can use this approach, you can read and combine> all the obs in a single step.> > Data _null_;* create two sample files;> file 'c:\park\tab1.txt' dlm='09'x;> retain a b c 1 d 'ddd' e 'eee';> *this is a quick way to assign initial values to variables;> put a b c d e;> run;> > Data _null_;> file 'c:\park\tab2.txt' dlm='09'x;> retain a b c 1111 d 'xxx' e 'yyy';> put a b c d e;> run;> > Data Readin;> infile 'c:\park\tab*.txt' dlm='09'x;> * I am using only part of the first node of the filename as a> wildcard. This reads only> * files named TAB something.txt If you want to read all of the files> in the folder, the> * your statement would be similar to 'c:\park\*.txt'> informat a b c d $3. e $3.;> input a b c d e ;> run;> > Proc Print;> run;> > > > Nat Wooding> Environmental Specialist III> Dominion, Environmental Biology> 4111 Castlewood Rd> Richmond, VA 23234> Phone:804-271-5313, Fax: 804-271-2977> > > > sas 9 bi user> <sas9bi@GMAIL.COM> > To> Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU> Discussion" cc> <SAS-L@LISTSERV.U> GA.EDU> Subject> Import Many text files into one> dataset> 05/08/2008 12:51> AM> > > Please respond to> sas 9 bi user> <sas9bi@GMAIL.COM> >> > > > > > > /*> Hey all,> > I am starting a project where I have about 100 text files separated by a> tab. I need to bring these files into one data set in SAS to analyze.> Each> file has 300K+ obs which is 30+ million records in my final dataset when I> am done.> > What is the best way to bring these in? I was thinking about doing it the> below, which I am sure is really bad idea but I am new to SAS so pls guide> me.> > */> > proc import datafile="importFile1.txt" out=privateDrive.import1 dbms=tab> replace;> getnames=yes;> run;> > /*Then I would change the above and do it agin like this:*/> > proc import datafile="importFile2.txt" out=privateDrive.import2 dbms=tab> replace;> getnames=yes;> run;> /*> > I would keep doing the above till I had my 100 data sets.> > Then I would run a merge of all the above data files into one file. Or a> proc sql union on all the files.> > I know, my idea is prob extremely inefficient so I open it up to you to> guide me! I bet my dumb way would take me a half day and that doesn't seem> too efficient!> > If you do have a suggestion, have pity on my, for eg don't just say, 'do a> array'. Since I am new at this I would prob not be able to follow high> level suggestions without some code sample.> > Thanks in advance for your wisdom!> > */> > > -----------------------------------------> CONFIDENTIALITY NOTICE: This electronic message contains> information which may be legally confidential and/or privileged and> does not in any case represent a firm ENERGY COMMODITY bid or offer> relating thereto which binds the sender without an additional> express written confirmation to that effect. The information is> intended solely for the individual or entity named above and access> by anyone else is unauthorized. If you are not the intended> recipient, any disclosure, copying, distribution, or use of the> contents of this information is prohibited and may be unlawful. If> you have received this electronic transmission in error, please> reply immediately to the sender that you have received the message> in error, and delete it. Thank you.
Windows Live SkyDrive lets you share files with faraway friends.