Hi
I am trying to Write a SAS code which would trigger an email when the disk size reaches 75%.
Kindly help me on this.
Hi,
You can use following logic:-
By using X command please fire "DF" command on Linux. It will give you details of all drives available on Linux. Pipe these details into a macro variable for your desired drive. If that macro variable is having value more than 75% fire following data step:-
filename outbox email "<Email id to whom email is send>";
data _null_;
file outbox
subject="Alert!!!!!! Disk space is 75% occupied"
;
put 'Your hard disk is 75% occupied. Please clean unused data.';
run;
In short over all logic will be:-
%macro check_hard_disk_capacity;
/*X command to check desired hard disk capacity and take it into macro variable*/
%if ¯o_varaible > 75 %then %do;
filename outbox email "<Email id to whom email is send>";
data _null_;
file outbox
subject="Alert!!!!!! Disk space is 75% occupied"
;
put 'Your hard disk is 75% occupied. Please clean unused data.';
run;
%end;
%mend;
I hope this helps.
Regards,
Abd.
Assume /tmp exceeds 75%, then how will you pipe this details into macro variable?
Speak to your IT group, they will have tools which can monitor drive space on a network and alert users when a drive is filling up. Don't try to re-invent the wheel on your own.
%macro send_email;
data _null_;
<X command to get values of disk space. Let us assume that this output is redirected to
file "out.txt." stored at "<Your location>";
run;
data input_data;
infile "<Your file location>"
firstobs = 1
dlm = ":"
missover
dsd
lrecl = 32767;
input
Description : $char128. /*string field of 128 chars long*/
bytes_Occupied : $char128. /*numbers of all types ints, floats, etc */
;
run;
data input_data;
set input_data;
Description=tranwrd(compress(Description,''),'#','no');
run;
proc sql;
select bytes_occupied into : free_bytes from input_data where description='Totalnooffreebytes';
select bytes_occupied into : total_bytes from input_data where description='Totalnoofbytes';
create table memory_stat
(
Total_no_of_free_bytes char(10000),
Total_no_of_bytes char(10000)
);
insert into memory_stat values("&free_bytes.","&total_bytes.");
quit;
data memory_stat(drop=Total_no_of_free_bytes Total_no_of_bytes);
set memory_stat;
Total_no_of_free_bytes_num=input(Total_no_of_free_bytes,20.0);
Total_no_of_bytes_num=input(Total_no_of_bytes,20.0);
Disk_consumption_in_perctage=(Total_no_of_bytes-Total_no_of_free_bytes)/Total_no_of_bytes*100;
call symputx("disk_utilization",Disk_consumption_in_perctage);
run;
%put &disk_utilization.;
%if &disk_utilization. >= 75 %then
%do;
filename outbox email "<Email id>";
data _null_;
file outbox
subject="Alert!!!!!! Disk space is 75% occupied"
;
put 'Your hard disk is 75% occupied. Please clean unused data.';
run;
%end;
%mend;
%send_email;
Not sure about Unix commnd but using windows command which is giving output as per attached snapshot we can code a mcaro mentioned above. Some calculations has to be done to get a macro parameter.I hope this will help.
If you have a SAS 9.4 platform installation then you may have SAS Environment Manager which can be configured to montitor resources such as disk space utilization, and generate alerts with an escalation scheme. Some resources that may be of interest to you if you want to use this approach:
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.