Date: Tue, 15 Nov 2011 16:42:32 -0500
Reply-To: "Bian, Haikuo" <HBian@NW7.ESRD.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Bian, Haikuo" <HBian@NW7.ESRD.NET>
Subject: Re: Create a SAS Dataset Containing Names of .csv Files in a
Specified Folder
In-Reply-To: <FA0550A1D186FF49BB0748CD711B17EDD910533BDB@SDPSMSX.QUALNET.ORG>
Content-Type: text/plain; charset="us-ascii"
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.