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 (November 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 15 Nov 2011 23:07:27 -0500
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: Create a SAS Dataset Containing Names of .csv Files in a
              Specified Folder

Use the PIPE engine on a filename to avoid creating a permanent file.

%let path=c:\csvfiles; filename csv pipe "dir /b &path\*.csv" ;

Or if you are submitting to a server that does not allow you to shell out with a PIPE or an X command then you could use a wildcard in the filename, but you will need to use the EOV and FILENAME options on your INFILE statement to be able to detect when a new file is started.

data files ; length filename fn $256 ; infile "c:\temp\*.txt" eov=eov filename=fn; input ; filename=fn; if eov then put (eov filename) (=); eov=0; run;

NOTE: This will only find files that are not empty!

On Tue, 15 Nov 2011 16:42:32 -0500, Bian, Haikuo <HBian@NW7.ESRD.NET> wrote:

>There was a mistake, now fixed: > >Options noxwait; >x 'dir c:\*.csv /b /d >c:\csv.txt'; >filename csv "c:\csv.txt"; >data csv; >infile csv; >input file_name $200.; >run; > >-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Bian, Haikuo >Sent: Tuesday, November 15, 2011 4:35 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Re: Create a SAS Dataset Containing Names of .csv Files in a Specified Folder > >Hi Mary, >The simplest way that I can think of is to invoke 'x' command. Here is one approach you could try: > >Options noxwait; >x 'dir *.csv c:\ /b /d >c:\csv.txt'; >filename csv "c:\csv.txt"; >data csv; >infile csv; >input file_name $200.; >run; > > >please replace 'c:\' with your own folder name. > > >Regards, >Haikuo > > >-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mary Rosenbloom >Sent: Tuesday, November 15, 2011 4:03 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Create a SAS Dataset Containing Names of .csv Files in a Specified Folder > >Hi all, > >I have a folder with several .csv files. I want to create a dataset >containing one record per .csv file, with a variable that contains the >filename of the .csv file. So for example, if D:\projects contains >data1.csv, data2.csv, data3.csv then I have a dataset with 3 observations, >containing one variable which has the values data1, data2, data3 (also >acceptable would be data1.csv, data2.csv, data3.csv). I have previously >been able to use similar code to tell me the names of subfolders, but now >I want the names of CSV files. Here is what I have tried: > >data pgms; > infile "C:\Projects\*csv" lrecl = 200 pad; > length progline $200; > input progline $char200.; > > progline = upcase(left(progline)); >run; > >I would appreciate code help as well as any references that you may have. >I recently purchased Burlew's "Reading External Data Files Using SAS", but >feel like I have a mountain to climb in terms of understanding this >concept. > >Thanks for your assistance. > >Cheers, >Mary R. >----------------------------------------- >Email messages cannot be guaranteed to be secure or error-free as >transmitted information can be intercepted, corrupted, lost, >destroyed, arrive late or incomplete, or contain viruses. The >Centers for Medicare & Medicaid Services therefore does not accept >liability for any error or omissions in the contents of this >message, which arise as a result of email transmission. > >CONFIDENTIALITY NOTICE: This communication, including any >attachments, may contain confidential information and is intended >only for the individual or entity to which it is addressed. Any >review, dissemination, or copying of this communication by anyone >other than the intended recipient is strictly prohibited. If you >are not the intended recipient, please contact the sender by reply >email and delete and destroy all copies of the original message.


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