|
On 8 May, 06:42, tobyd...@HOTMAIL.COM (toby dunn) wrote:
> Your looking for the FileVar option on the Infile Statement.
>
> 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: Wed, 7 May 2008 23:51:29 -0500
> > From: sas...@GMAIL.COM
> > Subject: Import Many text files into one dataset
> > To: SA...@LISTSERV.UGA.EDU
>
> > /*
> > 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!
>
> > */
>
> _________________________________________________________________
> Windows Live SkyDrive lets you share files with faraway friends.http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_R...- Hide quoted text -
>
> - Show quoted text -
Totally untested, but try something like this:
%let path=C:\files;
%let numfiles=100;
%macro imp (count=);
proc import datafile="&path\importfile&count..txt"
out=privatedrive.import&count dbms=tab
replace;
getnames=yes;
run;
%mend imp;
%macro cycle;
%local x;
%let x=1;
%do count=1 to &numfiles;
%imp (count=&x);
%let x=%eval(&x+1);
%end;
%mend cycle;
%cycle;
proc sql noprint;
create table names as
select distinct memname
from dictionary.columns
where lowcase(libname) eq "work"
and lowcase(memname) contains "importfile"
;
select strip(memname) into :tomerge separated by ' '
from names
;
quit;
data final;
merge &tomerge;
run;
|