Date: Sun, 12 Apr 2009 12:53:55 -0400
Reply-To: Michael Raithel <michaelraithel@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Michael Raithel <michaelraithel@WESTAT.COM>
Subject: Re: Importing multiple files from multiple folders
In-Reply-To: <200904121155.n3CAnGnE020886@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
Dear SAS-L-ers,
Priyanka Singh posted, in part, the following:
<<Priyanka's entire posting can be found beneath the Sig line>>
> I am trying to import multiple from a folder. However, I have
> folders inside that folder. So first I want to read the
> contents of main folder and using the name of the folders
> inside it , enter into each folder and read the files. This
> is where I have my real files. But the following code does
> not seem to work :
>
Priyanka, unfortunately, I do not have the time to crawl through your SAS code and resolve its specific issue(s):-( However, if you continue to be confounded by this problem and other 'L-ers cannot help you out, I have a suggestion.
SAS 9.2 offers the new SCAPROC Procedure, which allows you to write your own SAS functions. See Chapter 22 in the SAS 9.2 Procedures Guide: http://support.sas.com/documentation/cdl/en/proc/61895/PDF/default/proc.pdf
One of the examples that is provided in the literature is a directory traversal with the gathering of file names--see Directory Traversal Example starting on page 441. Directory traversals are always tricky, because the best way to perform them is with recursion. PROC SCAPROC provides the ability to fairly easily facilitate recursion in a SAS program.
So, perhaps there is future for PROC SCAPROC in your SAS programs!
BTW, SAS Sharpie Peter Eberhardt presented a good introductory paper on PROC SCAPROC at SAS Global Forum 2009:
A Cup of Coffee and Proc FCMP: I Cannot Function Without Them
http://support.sas.com/resources/papers/proceedings09/147-2009.pdf
Priyanka, best of luck in all of your SAS endeavors!
I hope that this suggestion proves helpful now, and in the future!
Of course, all of these opinions and insights are my own, and do not reflect those of my organization or my associates. All SAS code and/or methodologies specified in this posting are for illustrative purposes only and no warranty is stated or implied as to their accuracy or applicability. People deciding to use information in this posting do so at their own risk.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Michael A. Raithel
"The man who wrote the book on performance"
E-mail: MichaelRaithel@westat.com
Author: Tuning SAS Applications in the MVS Environment
Author: Tuning SAS Applications in the OS/390 and z/OS Environments, Second Edition
http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=58172
Author: The Complete Guide to SAS Indexes
http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=60409
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The road to a friend's house is never long. - Danish Proverb
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<<Priyanka's entire original posting>>
> Dear all,
>
> I am trying to import multiple from a folder. However, I have
> folders inside that folder. So first I want to read the
> contents of main folder and using the name of the folders
> inside it , enter into each folder and read the files. This
> is where I have my real files. But the following code does
> not seem to work :
>
> **************************************************************
> *************
> filename indata pipe 'dir J:\1999\199901\Snapshot\1999\Jan /b';
>
> data file_list;
> length fname $20;
> infile indata truncover end=last; /* infile statement for
> file names */ input fname $20.; /* read the file names from
> the directory */
> i+1;
> call symput('fname'||trim(left(put(i,8.))),scan(trim(fname),1,'.'));
> call symput('pext'||trim(left(put(i,8.))),trim(fname));
> if last then call symput('total',trim(left(put(i,8.))));
> run;
>
> %macro test;
> %do j=1 %to &total;
>
> filename indat pipe 'dir
> J:\1999\199901\Snapshot\1999\Jan\&&pext&j /b';
>
> data file_list&j;
> length fname1 $20;
> infile indat truncover end=last; /* infile statement for file
> names */ input fname1 $20.; /* read the file names from the
> directory */
> j+1;
> call
> symput('fname1'||trim(left(put(j,8.))),scan(trim(fname1),1,'.'));
> call symput('DS'||trim(left(put(j,8.))),trim(fname1));
> if last then call symput('total1',trim(left(put(j,8.))));
> run;
>
> %do k=1 %to &total1;
> proc import
> datafile="J:\1999\199901\Snapshot\1999\Jan\&&pext&j\&&DS&k"
> out=_&&fname&j_&&fname1&k
> dbms=dlm replace;
> delimiter='|';
> getnames=no ;
> run;
>
> %end;
> %end;
> %mend;
>
> /* Invoke the macro */
>
> %test
> **************************************************************
> **************
>
>
> The doesn't seem to work inside the macro:
> filename indat pipe 'dir
> J:\1999\199901\Snapshot\1999\Jan\&&pext&j /b';
>
> The error given is:
> Stderr output:
> 'pext' is not recognized as an internal or external command,
> operable program or batch file. 'j' is not recognized as an
> internal or external command, operable program or batch file.
> NOTE: 28 records were read from the infile INDAT.
> The minimum record length was 0.
> The maximum record length was 50.
>
>
>
> Please let me know the problem.
>
> Thanks & Regards,
> Priyanka
>