Date: Mon, 28 Feb 2011 17:47:42 -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
Content-Type: text/plain; charset=ISO-8859-1
What sort of layout are we talking? Fixed column (ie, 1-8 is respondent ID,
9-12 is year, etc.)? Whatever that layout is, read the documentation on
reading text files; it's something like:
@1 respondent $8.
@9 date MMDDYY8.
@17 field1 $3.
@20 field2 $3.
etc. The SAS documentation is pretty thorough on this; start with
or in short form
If you want to read in many files, use a wildcard:
length file_name $500;
infile "c:\tempfiledir\*.txt" filename=file_name;
datestamp = scan(file_name,-3,' .');
I think that would get the date from the filename (if I constructed my scan
right and your data is accurate; it works on the three listed below). The
code above assumes you have a layout defined (put that in place of
<variables>) and that you have a directory somewhere with your text files,
and want to read all of the text files in that directory in; otherwise you
may need a more complex wildcard or other method of reading.
On Mon, Feb 28, 2011 at 5:32 PM, Nuria Chapinal <firstname.lastname@example.org> wrote:
> 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!