LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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?
Comments:   To:
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 );

data attrib; infile "D_&file" firstobs=8 truncover end=eof; attrib name $32 type $10 dec 8 label $40. ; input name type dec label $40.; file "&" ; if _n_=1 then put "date &file;" /"infile '" "&file" "' dsd ;" /'input' ; put name @; if upcase(type) ne 'NUMERIC' then put '$ ' @; if eof then put ';' / 'run;'; run; %inc "&"; %mend;

Then read the list of files and call it once for each file pair.

filename files pipe "dir /b D_*"; data _null_; infile files truncover; input file $40.; call execute( '%input(' || file || ')' ); run;

On Jan 19, 5:53 pm, slightmoon <> 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 > names. > 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' > > 1,2,3,4,5,6, > 11,22,33,44,55,66 > ............. > > 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 > things. > > Millions of thanks!!!

Back to: Top of message | Previous page | Main SAS-L page