Date: Tue, 1 Sep 2009 03:51:17 -0700
Reply-To: "Richard A. DeVenezia" <rdevenezia@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <rdevenezia@GMAIL.COM>
Subject: Re: regarding csv files
In-Reply-To: <dfa3eef6-610e-417e-b53e-0fbafe338340@l35g2000pra.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
On Sep 1, 3:43 am, vinodh <vinodh...@gmail.com> wrote:
> how to read multiple csv files(variables are not same in all files)
> into sas from a folder using macros
Vinodh:
You _do not_ need macro. A _null_ DATA Step can EXECUTE an IMPORT
procedure for each file read from a *.csv DIR listing.
--------------------------------------------
* create some csv files;
data one;
array v(10) (1:10);
run;
data two;
array v(5) (1:5);
array w(5) (11:15);
run;
data three;
array x(10) (1:10);
run;
%let PATH = %sysfunc(pathname(WORK));
proc export data=one file="&PATH.\one.csv";
proc export data=two file="&PATH.\two.csv";
proc export data=three file="&PATH.\three.csv";
run;
proc sql;
drop table one,two,three;
quit;
* import each csv file into a like-named table;
filename LISTING pipe "DIR /B &PATH.\*.CSV";
data _null_;
infile LISTING _infile_=filename;
input;
tablename = substr(filename,1,length(filename)-4);
submit_statement = catt
( 'PROC IMPORT'
, ' file=', quote("&PATH.\"||filename)
, ' out=', tablename
, ';run;'
);
call execute (submit_statement);
run;
--------------------------------------------
Richard A. DeVenezia
http://www.devenezia.com