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 (June 2002, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 17 Jun 2002 05:38:34 -0700
Reply-To:     Tim Braam <timothy.j.braam@CENSUS.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Tim Braam <timothy.j.braam@CENSUS.GOV>
Organization: http://groups.google.com/
Subject:      Re: A great problem in writing SAS program...
Content-Type: text/plain; charset=ISO-8859-1

Something close to this ought to work. You'll need to change the %LET to point to the directory where the files are stored, and possibly change the INFILE and FILE statements in the LOOP macro to make sure they generate valid filenames on your system (I used Win2k to develop the code).

WARNING: This code REPLACES the existing files. If you want to test, comment out the FILE statement and use the one that is currently commented, which will create new files.

Tim Braam

%let dir=c:\junk\deleteme\ ;

data _NULL_; length fname $40 ; rc=filename("mydir","&dir"); did=dopen("mydir"); memcount=dnum(did); fname=''; memcount=dnum(did); if memcount > 0 then do ; do i = 1 to memcount ; fname=dread(did,i); if index(fname,'over.details.') then do ; k+1 ; date=scan(fname,3,'.') ; call symput('date'||trim(left(put(k,3.))),trim(left(date))) ; call symput('file'||trim(left(put(k,3.))),trim(left(fname))) ; end ; call symput('nfile',trim(left(put(k,3.)))) ; end; end; rc=dclose(did); run ;

%macro loop ; %do i = 1 %to &nfile ; data _NULL_ ; file "&DIR.&&file&i" ; /* comment to preserve existing files */ /*file "&DIR.new.&&file&i" ; */ /*un-comment to create new files */ infile "&DIR.&&file&i" ; input id $ quota ; date = "&&date&i" ; put @1 date $10. @12 id $8. quota ; run; %end ; %mend ; %loop;

"YCF" <s007422@cuhk.edu.hk> wrote in message news:<aejhnl$1l9u$1@ijustice.itsc.cuhk.edu.hk>... > Hello all, > I have a great problem in writing SAS program... > Situation: Now, I have more than 300 data files named > over.details.2001-04-09 > over.details.2001-04-10 > ...... > over.details.2002-03-31 > The contents of each of them are like this: > ID quota > s004211 25 > a551313 42 > ...... > > Now I am requied to insert a column called "DATE" , which refer to their > FILENAME, in each data file, so they become > DATE ID quota > 2001-04-09 s004211 25 > 2001-04-09 a551313 42 > ...... > > I think this is quite difficult, but is it possible to do this ? Thanks > very very much for your help!!!!


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