Date: Tue, 19 Jan 2010 17:09:09 -0800
Reply-To: Tom Abernathy <tom.abernathy@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Tom Abernathy <tom.abernathy@GMAIL.COM>
Subject: Re: read and merge lots of txt files, macro?
Content-Type: text/plain; charset=ISO-8859-1
I am not sure what good an excel file would do you.
It also seems strange that your filenames do not have extensions.
If you make a macro that takes as input the filename and then reads
the descriptor file and generates code to read the data file.
Something like this might work.
%macro input( file );
infile "D_&file" firstobs=8 truncover end=eof;
attrib name $32 type $10 dec 8 label $40. ;
input name type dec label $40.;
file "&file..sas" ;
if _n_=1 then put
/"infile '" "&file" "' dsd ;"
put name @;
if upcase(type) ne 'NUMERIC' then put '$ ' @;
if eof then put ';' / 'run;';
Then read the list of files and call it once for each file pair.
filename files pipe "dir /b D_*";
infile files truncover;
input file $40.;
call execute( '%input(' || file || ')' );
On Jan 19, 5:53 pm, slightmoon <lvhome2...@gmail.com> wrote:
> 1000+ txt files. two types. Type one file contains a list of varible
> names (character var). Type two file contains columns of real data
> with ','. I need to read in all txt files into sas files, pair up the
> one has Var names with the one has read number. Eventually I will
> creat new dataset with columns of data and the first row is the var
> For example, the file 'D_Ctable_3_2000' is like:
> title wording...
> (blank line)
> (blank line )
> VARIABLE FIELD DEC. VARIABLE
> NAME TYPE POS. DESCRIPTION
> --------------- ------- ----
> (row8) Sales Numeric 0 blah,blah
> Prices Numeric 0 blah,blah
> Year Numeric 0 blah,blah
> MONTH Numeric 0 blah,blah
> State Numeric 0 blah,blah
> market Numeric 0 blah,blah
> Then the second type of files are numbers only, column by column, such
> as 'C_table_3_2000'
> I want to read in all files, pair 'D_C_table_3_2000' with
> "C_table_3_2000", create 'table_3_2000' which contains both var names
> and values. My whole set of data files are titled as
> 'D_C_table_3_2000', 'D_H_table_6_2008', etc..
> I have a macro which saves file names into a excel file with name and
> path. It just I need to subsitute Proc Import with Data step since I
> want to use "firstobs=8" "missover" 'infile var $ 1-17', this kind of
> Millions of thanks!!!