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 (September 2009, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: vinodh <>
In-Reply-To:  <>
Content-Type: text/plain; charset=ISO-8859-1

On Sep 1, 3:43 am, vinodh <> wrote: > how to read multiple csv files(variables are not same in all files) > into sas from a folder using macros


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

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