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 (January 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 25 Jan 2007 13:56:55 -0800
Reply-To:     "StephenTGallagher@gmail.com" <StephenTGallagher@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "StephenTGallagher@gmail.com" <StephenTGallagher@GMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: loop through all files in dir for inclusion in macro
Comments: To: sas-l@uga.edu
In-Reply-To:  <51sjtnF1m5nb6U1@mid.individual.net>
Content-Type: text/plain; charset="iso-8859-1"

On Jan 25, 3:55 pm, "Richard A. DeVenezia" <rdevene...@wildblue.net> wrote: > StephenTGallag...@gmail.com wrote: > > I assume this is a common question, but excuse my foolishness for not > > being able to find an answer on the list or online. Perhaps my search > > criteria are wrong. > > > I have a directory with ten (abitrary number...could be hundreds) of > > files, whose naming convention is not consistent, but, more or less, > > extension is .txt or .csv. > > > I have a macro to, for example, import all of these files. Currently I > > am hardcoding the filenames. I am sure this is a tremendous waste of > > time. > > > I have come across code that will return every filename within a > > directory on the sas site. I am including it below for reference, but > > for the rest of my question please skip from ****code begins**** toWhile the dopen way works, it can be tedious and does not allow for direct > filtering via a wildcard specification. > > A very common method is to get a list of file from a directory listing and > dispatching what to do with the data from that. If all the data files have > a common format and are to be read into a single SAS table, or appended to a > single SAS table, there are other strategies. > > case 1. > all files same structure. > > * care about keeping the filename the data came from; > data newdata; > length filename $200; > infile 'c:\mydata\thisweek\*.txt' filename=datafile; > filename = datafile; > input x y z a b c; > run; > > * dont care; > data newdatavague; > infile 'c:\mydata\thisweek\*.txt' ; > input x y z a b c; > run; > > case2. > all files processed independently > > %macro consume(file=); > %put file=&file; > %mend; > > %let path = c:\temp; > %let action = consume; > > filename dirlist pipe "dir /b &path.\*.txt"; > data _null_; > length command $200; > infile dirlist _infile_=filename; > input; > command = cats( '%', "&action(file=&path.\", filename, ')'); > put command=; > call execute ('%nrstr(' || trim(command) || ')'); > run; > > -- Richard A. DeVeneziahttp://www.devenezia.com/

oh, this is very helpful, thanks.

i will attempt to implement and post back with any clarifications i might need.

thank you!

--sg


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