Date: Tue, 22 Jan 2008 08:22:17 -0600
Reply-To: "data _null_," <datanull@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "data _null_," <datanull@GMAIL.COM>
Subject: Re: Reading a directory of files
In-Reply-To: <11460254-f3cd-4ae2-814c-9a89461125ba@v17g2000hsa.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
The thing that annoys me about using DIR is that unless you include
the /S option the "name" does not include the path. I suppose one
could argue that if you don't include /S then you should know the
path, while that is technically true but I don't like to think that
hard. I like the ATTRIB command it supports /S as well but the output
always contains the fully qualified name.
%let Path = .;
%let Mask = *.sas;
filename dirlist pipe %unquote(%bquote('dir /b "&Path\&mask"'));
filename dirlist list;
data _null_;
infile dirlist;
input;
list;
if _N_ gt 10 then stop;
run;
filename ft17f001 pipe "attrib ""&Path\&mask""";
data work.files;
infile ft17f001 truncover;
input @12 filename $256.;
run;
On Jan 22, 2008 6:26 AM, ajs2004@bigfoot.com <ajs2004@bigfoot.com> wrote:
> If you're using Windows, could try
>
> Sample 24820: Creating a Directory Listing Using SAS for Windows
> http://support.sas.com/kb/24/820.html
>
> I think that macro doesn't handle variations based on two-digit or
> four-digit year in the DIR output. I have an adapted version that
> deals with this (and a couple of other problems).
> __
>
> It's simpler to take the simpler /b 'bare' format output from DIR -
> something like:
>
> filename dirlist pipe 'dir /b /a /s <directory>'; /* Put in actual
> value for <directory> */
>
> data dirlist;
> infile dirlist truncover;
> input dirfile $char260.;
> run;
>
> but that only gets you the names, not the file attributes (size, dates
> etc). You can then call system routines to get the file attributes -
> which is actually rather better than trying to process fiddly (and
> less informative) output from the DIR command. I've tried that based
> on:
>
> http://www.devenezia.com/downloads/sas/sascbtbl/file_management.sas
>
> from Richard A. DeVenezia at http://www.devenezia.com/downloads/sas/sascbtbl/
>
>
>
> On Jan 21, 9:22 pm, nicole.d.b...@WELLSFARGO.COM (Nicole Bibb) wrote:
>
> > I need to read a directory of files and save the filenames in dataset to
> > be read into a macro. I am not sure how to store the file names into a
> > dataset after reading the directory. Any suggestions or code would be
> > helpful thanks
>
|