Thank you all for the response! I have found a way to print members of folder (see code below) and later used proc contents to search for specific SAS dataset variables. =================================================================================================== %macro getdirmembers_detail(dirpath,outdata=dirmembers,errdata=getdir_errors); %global getdirrc subdirflag; %let subdirflag=0; data &outdata(keep=member memname memext memcount dirpath dirlevel memtype owner group permissions lastmoddt filesize) &errdata(keep=member dirpath dirlevel errmsg); length member memname $ 300 memext $ 40 dirpath $ 600 memtype $ 4 errmsg $ 200 owner group permissions lastmod $ 40; format lastmoddt datetime20. ; label member='Member' memname='Member Name' memext='Member Extension' memcount='Members in Folder' dirpath='Parent Path' memtype='Dir or File' owner='Owner' group='Group' permissions='Permissions' lastmoddt='Last Mod Date' filesize='File Size(bytes)'; dirpath=strip("%str(&dirpath)"); dirlevel=countw(dirpath,'/'); call symputx('getdirrc','0','G'); call symputx('getdirmsg',' ','G'); /*----------------------------------------------------------------- * Check to see if the directory exists. If so, proceed here. *-----------------------------------------------------------------*/ if fileexist(dirpath) ne 0 then do; rc=filename('extdir',dirpath); did=dopen('extdir'); /*----------------------------------------------------------------- * After attempting to open the directory, see if it succeeded * If so proceed here. Get the number of members found into memcount *-----------------------------------------------------------------*/ if did then do; memcount=dnum(did); /*----------------------------------------------------------------- * Loop through the members and figure out what they are. *-----------------------------------------------------------------*/ do i=1 to memcount; member=dread(did,i); /*----------------------------------------------------------------- * First, look for some bad actors. May deal with these later. *-----------------------------------------------------------------*/ if countc(member,"'")=1 then do; errmsg='Member contains a single quote and has been excluded from analysis'; output &errdata; end; else if countc(member,'"')=1 then do; errmsg='Member contains a double quote and has been excluded from analysis'; output &errdata; end; else if index(member,'(') and not index(member,')') then do; errmsg='Member contains a left parenthesis but no right parenthesis so has been excluded from analysis'; output &errdata; end; else if index(member,')') and not index(member,'(') then do; errmsg='Member contains a right parenthesis but no left parenthesis so has been excluded from analysis'; output &errdata; end; else if index(member,'*') then do; errmsg='Member contains an asterisk so has been excluded from analysis'; output &errdata; end; /*----------------------------------------------------------------- * Process each member to see if a directory or a file *-----------------------------------------------------------------*/ else do; tempname=strip(dirpath) || '/' || strip(member); trc=filename('testfile',tempname); *put 'NOTE: Return code on filename function=' trc; fid=fopen('testfile','I'); /*--------------------------------------------------------- * Attempt to open as a file. If it is, get attributes *---------------------------------------------------------*/ if fid then do; memtype='FILE'; memext=scan(member,-1,'.'); memname=scan(member,1,'.'); /*--------------------------------------------------------- * Note that the position of these attributes are different * per operating system. This is set up for Unix/Linux *---------------------------------------------------------*/ owner=finfo(fid,foptname(fid,2)); group=finfo(fid,foptname(fid,3)); permissions=finfo(fid,foptname(fid,4)); lastmod=finfo(fid,foptname(fid,5)); lastmoddt=input(lastmod,datetime20.); filesize=finfo(fid,foptname(fid,6)); fc=fclose(fid); output &outdata; end; /*----------------------------------------------------------------- * If not a directory and cannot open as file, it is either an * unreadable file or we do not have permission. Write to error * file. *-----------------------------------------------------------------*/ else do; tid=dopen('testfile'); /*--------------------------------------------------------- * If the member opens as a diretory, then flag it and output. *---------------------------------------------------------*/ if tid then do; memtype='DIR'; memname=member; memext=' '; call symputx('subdirflag','1','G'); /*--------------------------------------------------------- * Note that the position of these attributes are different * per operating system. This is set up for Unix/Linux *---------------------------------------------------------*/ owner=dinfo(tid,doptname(tid,2)); group=dinfo(tid,doptname(tid,3)); permissions=dinfo(tid,doptname(tid,4)); lastmod=dinfo(tid,doptname(tid,5)); lastmoddt=input(lastmod,datetime20.); tc=dclose(tid); output &outdata; end; else do; put "WARNING: " member " could not be opened"; errmsg='fopen and dopen failed for file ' || tempname; output &errdata; end; end; rc=filename('testfile'); end; /* end of else do for each member */ end; /* End do i=1 to memcount */ cid=dclose(did); end; /* End If did */ /*----------------------------------------------------------------- * If Directory open failed, then issue a message. * probably permissions. *-----------------------------------------------------------------*/ else do; getdirmsg=sysmsg(); errmsg=getdirmsg; if errmsg ne ' ' then put errmsg; else put "WARNING: " dirpath " could not be opened"; call symputx('getdirmsg',strip(getdirmsg),'G'); call symputx('getdirrc','4','G'); output &errdata; end; rc=filename('extdir'); end; /* End If fileexist */ /*----------------------------------------------------------------- * If file could not be found, issue a message. *-----------------------------------------------------------------*/ else do; put "ERROR: " dirpath " does not exist."; getdirmsg=sysmsg(); errmsg=getdirmsg; call symputx('getdirmsg',strip(getdirmsg),'G'); call symputx('getdirrc','12','G'); output &errdata; end; run; %mend getdirmembers_detail;
... View more