i came across this code which is supposed to help me monitor my disk space on my sas server, i tried making adjustments on the code to suite my environment but its not making any sense to me especially allocating the file directories and the type of file directories being used in the code itself. can anybody please take a look at this code and see if they can explain the files directory allocations, thanks.
/************************************************/
COMPANY NAME: HEALTH PARTNERS OF PHILADELPHIA *
COMPANY SAS SERVER NAME: HPSAS2 *
RUNNING ON WINDOWS 7 PLATFORM *
/************************************************/
*-routine to check global disk space--;
*this calls the space command and outputs it to
a flat file which SAS can read.;
%macro hpsasserver(drive);
x "@hpsas2:[mastgr]space.com /
out=asresscr:[mastgr]temp.asc";
data space1 ;
infile "asresscr:[mastgr]temp.asc"
missover;
*lrecl=86, variable length;
input drive $7-15 maximum 22-29
used 38-45 free 53-60;
run;
*---here is a routine which writes the code to
call the macros which are defined later on in
this program. After much experimentation with
symput statements and the like, this routine
works best.;
data _null_;
file 'asresscr:[mastgr]macro.sas' noprint;
set space1;
if drive="&drive";
x = length(drive) + 11;
xx = x-3;
put@1 '%catinhat(' @11 drive $9.
@x ');'
/ @1 '%seuss(' @8 drive $9. @xx ','
@xx+1 maximum 8. @xx+9 ','
@xx+10 used 8. @xx+19 ');' ;
run;
%mend hpsasserver;
%MACRO CATINHAT(DRIVE);
x "dir/size=allocation/date/own/nohead/
notrail/width=(filename=100,
display=195,size=10)
/out=asresscr:[mastgr]&DRIVE..asc
&DRIVE.:[000000...]";
%MEND CATINHAT;
/*EXECUTION*/
%hpsasserver(OTHSAS);
%include 'asresscr:[mastgr]macro.sas';
x 'del asresscr:[mastgr]OTHSAS.ASC;*';
%MACRO SEUSS(DRIVE,BIG,USED);
data a;
infile "asresscr:[mastgr]&DRIVE..asc"
lrecl=195 missover;
input blob $ 1-100 size 103-112
@115 L date11. @115 dd 2. @118 mmyy $8.;
*---count files where users have implemented
tight file protection. A high number of them
warrants inquiry. ;
if size=. then protectd=1; else protectd=0;
*--identify the directory and the user--;
length dir $ 50 userid $ 8 filetype $ 10;
*first, get the directory;
a = index(blob,"[") + 1;
b = index(blob,"]") - 1;
c = (b-a)+1;
dir = substr(blob,a,c);
*--now we can identify the userid--;
d = index(dir,".") - 1;
if d > 1 then userid = substr(dir,1,d);
else userid = dir;
*----identify the file name and extension---;
e = length(blob);
h = index(blob,";") - 1;
filename = substr(blob,(b+2),(e-(b+1)));
dot = index(filename,".");
fun = length(filename);
nuf = substr(filename,(dot+1),(fun-dot));
*this is the extension + version number;
ufn = index(nuf,";") - 1;
*this is the byte where extension ends;
fufu = length(nuf);
filetype = substr(nuf,1,ufn);
if filetype='SYS' then userid='SYSTEM';
*--identify the version for need-to-purge
detection--;
i = e - (h+1);
*h+1 is where the semicolon is in the filename;
version = input(substr(blob,(h+2),4),5.);
blob2 = substr(blob,1,h);
*this is the filename without the version
number;
*keep the filesize data of files we could purge;
if lag(blob2) = blob2
then purge = lag(size);
else purge=0;
*--edit an artifact from incomplete journal
files;
if purge > (size*5000) then purge = size;
*[potential underreporting or other minor
inaccuracy may result, but this is better than
an occassional wildly high number];
*-----flag old files----------------;
*create current date;
ahora=today();
*measure the age of the file in days;
age = ahora - l;
*--now do age buckets - 1 for space and 1 for
the number of files. create one set of vars
for: 2 days, 3-90 days, and over 90 days;
array ned{6} mo6_cnt mo6_sp mo3_cnt mo3_sp
x48_cnt x48_sp;
do n=1 to 8;
ned{n}=0;
end;
if age le 2 then do;
x48_cnt = 1;
x48_sp = size;
end;
else if (2 < age < 91) then do;
mo3_cnt = 1;
mo3_sp = size;
end;
else if age > 90 then do;
mo6_cnt = 1;
mo6_sp = size;
end;
keep dir freq size protectd purge userid
filetype mmyy mo6_cnt mo6_sp mo3_cnt mo3_sp
x48_cnt x48_sp;
run;
*---calculate the size of system files;
proc summary data=a nway;
var size;
output out=xxx(drop=_type_) sum=sizex;
run;
data marvin;
set xxx;
sizez = ( &used - sizex);
*total used space minus all space SAS can
account for due to priveleges;
call symput("SYSX",sizez);
run;
*-------now apply the calculated system file
space, being careful not to doublecount;
proc sort data=a;
by userid;
run;
data marco;
set a;
by userid;
length freq size mo6_cnt mo6_sp 8;
if first.userid and userid='SYSTEM' then do;
size = ( &SYSX / 1);
mo6_sp = size;
freq = 1;
mo6_cnt = 1;
end;
else if userid='SYSTEM' then do;
size=0;
mo6_sp=0;
freq=1;
mo6_cnt=1;
end;
else freq = 1;
run;
*----summarize-----------;
proc summary data=marco missing;
class userid filetype dir;
var freq size protectd purge mo6_cnt mo6_sp
mo3_cnt mo3_sp x48_sp x48_cnt;
output out=b sum=;
run;
*----create report---;
data c;
set b;
if _type_=0 then do;
userid='ZZZZZZZZ';
filetype='ZZZ';
dir='ZZZ';
end;
if _type_=1 then do;
userid='ZZZZZZZZ';
filetype='ZZZ';
end;
if _type_=2 then do;
userid='ZZZZZZZZ';
dir = 'ZZZ';
end;
if _type_=3 then userid='ZZZZZZZZ';
if _type_=4 then do;
filetype='ZZZ';
dir = 'ZZZ';
end;
if _type_=5 then filetype='ZZZ';
if _type_=6 then dir='ZZZ';
pct = (size / &big ) * 100;
pct2= (purge / size) * 100;
length whom $ 8;
whom = userid;
run;
*-----userid level summary-------------;
proc sort data=c out=d;
by descending _type_ descending size;
where _type_=0 or _type_=4;
run;
proc print data=d noobs split="*";
var userid whom freq protectd size pct purge
pct2 x48_cnt x48_sp mo3_cnt mo3_sp
mo6_cnt mo6_sp;
format size comma10.
purge mo6_sp mo3_sp x48_sp comma9.
freq comma6.
mo6_cnt mo3_cnt x48_cnt comma5.
pct pct2 protectd 3.
whom $whom. ;
*($whom is a format which takes a userid and
returns the user name and telephone extension);
label userid = 'User Id'
whom = 'Name & Phone Extension'
freq = '# Files'
protectd= 'Pro-*tected'
size = 'Blocks'
pct = 'Pct'
purge = 'Blocks*To*Purge'
pct2 = 'Pct'
mo6_cnt = 'Files*Over 3*Mos'
mo6_sp = 'Space*Over 3*Mos'
mo3_cnt = 'Files*Up To 3*Mos'
mo3_sp = 'Space*Up To 3*Mos'
x48_cnt = 'Files*2 Days'
x48_sp = 'Space*2 Days' ;
title "&DRIVE SPACE USAGE REPORT BY USER ID";
run;
*------------summary by directory--------------;
*screen out little stuff...look for large files
and sas work directories;
data xx;
set c;
if _type_=1;
if (size > 49999)
or (index(dir,"SAS$WORK") > 0);
pct = (size / &big ) * 100;
pct2= (purge / size) * 100;
run;
proc sort data=xx;
by dir;
run;
proc print data=xx noobs split="*";
var dir freq protectd size pct purge pct2
x48_cnt x48_sp mo3_cnt mo3_sp mo6_cnt
mo6_sp;
format size comma10.
purge mo6_sp mo3_sp x48_sp comma9.
freq comma6.
mo6_cnt mo3_cnt x48_cnt comma4.
pct pct2 protectd 3.
whom $whom. ;
label dir = 'Directory'
freq = '# Files'
protectd= 'Pro-*tected'
size = 'Blocks'
pct = 'Pct'
purge = 'Blocks*To*Purge'
pct2 = 'Pct'
mo6_cnt = 'Files*Over 3*Mos'
mo6_sp = 'Space*Over 3*Mos'
mo3_cnt = 'Files*Up To 3*Mos'
mo3_sp = 'Space*Up To 3*Mos'
x48_cnt = 'Files*2 Days'
x48_sp = 'Space*2 Days' ;
title "&DRIVE SPACE USAGE REPORT BY DIRECTORY
- SAS$WORK DIRECTORIES OR OTHER FILES OVER
49,999 BLOCKS";
run;
*------------summary by file type--------------;
*summarize again, and recode to simplify
results.;
proc summary data=marco missing nway;
class filetype;
var size protectd purge mo6_cnt mo6_sp mo3_cnt
mo3_sp x48_sp x48_cnt;
output out=bb sum=;
run;
data xxx;
set bb;
if filetype in
('JOU','SAS','DAT','LIS','LOG','TXT','TDS',
'SSD','COM','MAI','SASEB$DATA','SASEB$CATA',
'SASEB$VIEW','SYS','TPU$JOURNAL') then do;
*absolutely nothing;
end;
else filetype='ALL OTHERS';
rename _freq_ = freq;
run;
proc summary data=xxx MISSING nway;
class filetype;
var size protectd purge mo6_cnt mo6_sp mo3_cnt
mo3_sp x48_sp x48_cnt freq;
output out=bb sum=;
run;
proc sort data=bb;
by descending _type_ filetype;
run;
data cc;
set bb;
by descending _type_ filetype;
if _type_=0 then
filetype='*** GRAND TOTAL ***';
pct = (size / &big ) * 100;
pct2= (purge / size) * 100;
run;
proc print data=cc noobs split="*";
var filetype freq protectd size pct purge pct2
x48_cnt x48_sp mo3_cnt mo3_sp mo6_cnt
mo6_sp;
format size comma10.
purge yr_sp mo6_sp mo3_sp x48_sp comma9.
freq comma6.
mo6_cnt mo3_cnt x48_cnt comma4.
pct pct2 protectd 3.
whom $whom. ;
label filetype= 'File*Type'
freq = '# Files'
protectd= 'Pro-*tected'
size = 'Blocks'
pct = 'Pct'
purge = 'Blocks*To*Purge'
pct2 = 'Pct'
mo6_cnt = 'Files*Over 3*Mos'
mo6_sp = 'Space*Over 3*Mos'
mo3_cnt = 'Files*Up To 3*Mos'
mo3_sp = 'Space*Up To 3*Mos'
x48_cnt = 'Files*2 Days'
x48_sp = 'Space*2 Days' ;
title "&DRIVE SPACE USAGE REPORT BY FILETYPE";
run;
proc datasets library=work nolist;
delete a b c d bb cc xx;
run;
%MEND SEUSS;
This appears to be a variation of a method published by Greg Mast in a paper titled "Managing Disk Space with SAS" (http://www2.sas.com/proceedings/sugi22/TRAINING/PAPER325.PDF). There are probably other versions "out there" as well. A close read of the document might be a good place to start.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.