Hello world, I'm fairly new to SAS and need some help. I'm trying to write a macro in EG that can open up a directory and create a data set that gives the size and file name of all files in that directory. I've seen some great examples in SAS papers but they require the pipe function and I don't have permission to use PIPE. So far I've had success in doing two things. 1) Get all the filename's written to the log. This is done with a macro I found on SAS support. %macro drive(dir,ext); %let filrf=mydir; /* Assigns the fileref of mydir to the directory and opens the directory */ %let rc=%sysfunc(filename(filrf,&dir)); %let did=%sysfunc(dopen(&filrf)); /* Returns the number of members in the directory */ %let memcnt=%sysfunc(dnum(&did)); /* Loops through entire directory */ %do i = 1 %to &memcnt; /* Returns the extension from each file */ %let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.); /* Checks to see if file contains an extension */ %if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&name) %then %do; /* Checks to see if the extension matches the parameter value */ /* If condition is true prints the full name to the log */ %if (%superq(ext) ne and %qupcase(&name) = %qupcase(&ext)) or (%superq(ext) = and %superq(name) ne) %then %do; %put %qsysfunc(dread(&did,&i)); %end; %end; %end; /* Closes the directory */ %let rc=%sysfunc(dclose(&did)); %mend drive; 2) Get the size of one file at a time. I used the previous macro's output to manually make macro variables. Then feed them into this code. %let Invoice=\\mydir; %let file1=<the file name returned by the last macro> data info; length infoname infoval $60; drop rc fid infonum i close; rc=filename("abc","&invoice.&file1."); fid=dopen("abc"); infonum=fnum(fid); do i=1 to infonum; infoname=foptname(fid,i); infoval=finfo(fid,infoname); output; end; close=fclose(fid); run; A major problem with this is it only handles one file at a time, and I need all of this information to go into one location so I can look for files with the same size. I know I could make this into a loop that will output a bunch of datasets but this doesn't seem very efficient. When I envision this is see the first macro storing all file names as individual macro variables. I know this can be done with a loop to update a %let statement <%let file&I. = maybe dread(&did,&I.)>. But the right side of this equality is a major road block for me. After getting the file names stored, I need to grab the file size. I'm having a hard time doing this because i know i need to use finfo() and I have a dopen() situation. Is there a way to trickle down so to speak? Stating at dopen() and eventually using fopen() so that I can use finfo(). Major Questions: How can I store system output functions as macro variable? How can I go from a dopen() situation to a finfo() situation? As a new programmer I'd really like guidance more than anything. I truly want to learn this not just have the code written for me. Any help would be much appreciated.
... View more