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 (February 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 28 Feb 2011 18:01:35 -0600
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: importint lots of txt files at once and taking the date from
              the title
Comments: To: Suzanne McCoy <>
In-Reply-To:  <>
Content-Type: text/plain; charset=ISO-8859-1

FWIW, you don't actually have to do three data statements :) Assuming you don't want to use the wildcard for some reason (like you couldn't establish a wildcard pattern that was useful), you can actually input multiple files in one filename statement, without suffering the 'stop at end of one file' that would happen if you put several filenames in one data step. There are two or more ways of doing this... the first is useful if you have a preset list, the second could be used with a varying list held in a text file or whatnot somewhere.

Quoted list of filenames: data whatever; infile "('stuff.txt', 'stuff1.txt', 'stuff2.txt')"; ... input ... run;

Using filename option, direct from the SAS docs:

data allsales; length fileloc myinfile $ 300; input fileloc $ ; /* read instream data */

/* The INFILE statement closes the current file and opens a new one if FILELOC changes value when INFILE executes */ infile file-specification filevar=fileloc filename=myinfile end=done;

/* DONE set to 1 when last input record read */ do while(not done); /* Read all input records from the currently */ /* opened input file, write to ALLSALES */ input name $ jansale febsale marsale; output; end; put 'Finished reading ' myinfile=;

datalines; external-file-1 external-file-2 external-file-3 ;


On Mon, Feb 28, 2011 at 5:49 PM, Suzanne McCoy <> wrote:

> *make 3 filename statements, 1 for each file; > > data inputfiles1; > infile xyz1 missover; > input @1 textstring $lrecl. @; > if scan(textstring,1,' - ' then > do; > *parse the string to get your stat name and your date; > *delete; > end; > else > do; > *input your numeric fields @1 firstfield 8. > etc.; > end; > run; > > ... > > data all; > set inputfiles1 inputfiles2 inputfiles3; > run; > > ** This is a shell and definitely may not be the most efficient but should > get you started; > > ________________________________________ > From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] On Behalf Of Nuria > Chapinal [nchapinal@YAHOO.COM] > Sent: Monday, February 28, 2011 6:32 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: importint lots of txt files at once and taking the date from the > title > > Hi, > > I have 3 batches of txt files in 3 different folders in my computer. They > are consistent within batch in the number of columns and their format and > the title format. All the columns are numerical. The title contains the > date. I want to import and append all the txt files belonging to the same > batch, and I want to create a column with the date in the SAS datasets. > > The titles look like these (one example of each batch): > close up activity - 11-03-2010 01-59.txt > close up heifer activity - 11-03-2010 01-49.txt > fresh cow activity - 11-03-2010 01-52.txt > > Any advice on how to start will be appreciated. I have no experience > importing txt files in SAS, only csv and excel.... > I can send example files if anyone is very keen to help out ;) > > Thanks in advance! >

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