Creating A Directory Listing Using SAS For Windows in TopDown Order
Creating A Directory Listing Using SAS For Windows in TopDown Order
Creating A Directory Listing Using SAS For Windows in TopDown Order
Here I present a SAS macro to Create a directory listing using SAS for Windows in TopDown order...
SAS Institute has provided a macro to Create a directory listing using SAS for Windows (http://support.sas.com/kb/24/820.html)....I
have added additional steps to massage the results and provide a report which gives the results in descending order of the file size....
I've used this macro to check for space issues on network folders at work....
I hope it suits your situation....
/*============================================================================*/
/* external storage references
/*============================================================================*/
/* run Windows "dir" DOS command as pipe to get contents of data directory */
/*############################################################################*/
/* begin executable code
/*############################################################################*/
/*Count the number of the Initial Directory levels in the Rootpath for eg. C:\Temp i.e. 2 */
data _null_;
initpath="&PATH";
dirlevels=count(initpath,'\')+1;
call symputx('lvlsinitpath',dirlevels);
run;
if dir_rec
then
path = left( substr( line, length( "Directory of" ) + 2 )) ;
else do ;
date = abs(input( scan( line, 1, &DELIM ), mmddyy10. )) ;
if post_meridian then time = time + '12:00:00'T ; /* add 12 hours to represent on 24-hour clock */
/* date/time filter */
/*============================================================================*/
/* add data for current directory path to cumulative report dataset
/*============================================================================*/
/*============================================================================*/
/* break association to previous path prior to next %DIRLISTWIN invocation
/*============================================================================*/
data dirlistSize;
length previous $ 100;
retain previous;
set dirlist;
%macro levels;
%do i=&lvlsinitpath. %to %eval(&maxlev -1);
select distinct level&i. AS Path, sum(size) as Size
format=comma10.2,sum(size)/(1024*1024) as SizeMB format=comma10.2,sum(size)/(1024*1024*1024) as SizeGB
format=comma10.2
from dirlistSize
where level&i. ne ''
group by level&i.
UNION
%end;
%mend levels;
%levels
data final;
set prefinal;
dirlevels=count(path,'\')+1;
/*Size filter*/
%if %length( &MAXSIZE ) > 0 %then %str( if sizeMB <= &MAXSIZE ; ) ;
%if %length( &MINSIZE ) > 0 %then %str( if sizeMB >= &MINSIZE ; ) ;
run;
%if &REPORT eq Y
%then %do ;
ods listing close;
ods html file="&OUT.";
title1 "Directory Listing and Size greater than &MINSIZE. (MB) " ;
title2 "at Location: &PATH" ;
proc report center data=TopDown headskip nowindows spacing=1 split='\' ;
column path size sizeMB sizeGB; * dirlevels;
define path / display width=17 'Path' ;
define size / display format=comma16.2 'Size in Bytes' ;
define sizeMB / display format=comma16.2 'Size in MB' ;
define sizeGB / display format=comma16.2 'Size in GB' ;
*define dirlevels / display 'Sub Directory Levels' ;
run ;
title ;
ods html close; ods listing;
%end ;
%mend DIRLISTWIN ;
%let outxls=C:\DirSpaceListing_&sysdate9..xls;