IMHO, you typically use email if you want to let others know about a problem. If it is only for you why not just create an exception or tracking report in a folder where you can just go and view it? Sending an email sounds like an unnecessary complication.
If you don't want to report with hard coded values then you will need to do something to establish boundaries for when to report.
If you are worried about extremes that occur intermittently you might look at the RANGE statistic for a time period. That is basically the largest value minus the smallest. So if the range is "large" you might have an extreme.
Another thing to look at might be Standard deviation but it is not as sensitive to one or two values if you have 1000s. But a single value 2 or 3 standard deviations from the mean might be an outlier.
You might do some investigation on a "large" set of data (several months perhaps) just to learn about the distributions of your data values to determine some likely basic rules and provide parameters.
Proc Means asking for mean, min, max, std, mode, median and maybe the Q1 and Q3 quantiles should show you a bit about your current data
Do you have some sort of change seasonally like temperature going down in winter and increasing in summer? If so you should create the summaries by groups that might reflect that.
What goes into your data makes a difference on what may be useful to look at. I worked with a lot of instrument data related to weather and soil conditions once upon a time to help diagnose possible instrument issues. So I had seasonality to set some bounds for "reasonable" values; some instruments had natural ranges such as humidity (really cannot go below 0 or over 100 but some conditions would make the instruments report that), or barometric pressure (0 would mean there is no local atmosphere). Others I looked at rates of change (air temperature is unlikely to go from 10 to 100 degrees in one hour).
The idea of what to check will tell you how to make the report. Generally a set of values, which would be in a data set, and rules on how to compare those values to your data flow.
How to report? Provide some actual rules you come up with after looking at your data.
Well, you would need to define what trigger levels would cause an email to be generated, but if you keep some kind of history of the average value of the columns you're interested in, that shouldn't be too difficult.
I find it easier to just use regular SAS to send emails rather than using SAS EG. Let me know if you need sample code for this.
What you would need to do, and there are other ways to do this, but this is what came to mind, is something along the lines of:
1. First you would run a Data step that compares the current maximum value to the average value and if that value is exceeded, then it sets a return code.
2. Second, you would code a step that executes conditionally -- if the return code is a certain value.
At a high level, it might look like this:
%LET Return_Code = 0;
DATA _NULL_
SET &Lib..Avg_Value_History;
IF Curr_Max_Value_Col_12 > Hist_Avg_Max_Value_Col_12 THEN
CALL SYMPUTX ('ReturnCode', 4, 'G');
RUN;
%IF %BQUOTE(&Return_Code) = 4 %THEN
%DO;
%Send_Alert_Email;
%END;
Jim
Below is some code from one of the jobs in my area. I'm not sure who wrote this; I might have done it differently, but hopefully it's sufficient as an example.
Some notes:
Please ask questions if you have any.
%macro gen_email(Email_Address_List, Sender, Environment, Table, Nbr);
FILENAME Mailbox EMAIL
to = ("&Email_Address_List")
from = "&Sender"
subject = "&environment Table Lock Alert! Please close *** &Table *** ASAP. (alert #&Nbr)"
;
%if &syserr > 0 %then
%do;
%put &Err1 occurred previous to the email step;
%end;
%else
%do;
/*email that no errors*/
DATA _NULL_;
FILE Mailbox;
put "/******************** automated message - do not reply to sender ********************/";
put " ";
put "Team,";
put " ";
put "&environment Table Lock Alert! Please close ASAP:";
put " ";
put " &Table ";
put " ";
put "This message will be sent every 3 minutes until table is closed.";
put " ";
put "This is alert #&Nbr..";
RUN;
%end;
%mend;
%gen_email(Some_Email@XXX.com, another_email@XXX.com, Development, Acct04p, 12);
Jim
P.S. The above assumes that you have something like the below in your SASV9.cfg file. In the below, you would replace "YYYY.XXX.org" with whatever server your organization uses for email.
/* set email options */
-EMAILSYS SMTP
-EMAILHOST YYYY.XXX.org
-EMAILPORT 25
If you're not sure what those values are, you can run the following, and the values will be written to the log.
PROC OPTIONS OPTION=(EmailSys EmailHost EmailPort);
RUN;
If the above are not in your SASv9.cfg, you can add that code to your cfg file, if you have access. If you don't have access, you can set those values inside your SAS program like so:
OPTION EmailSys=SMTP;
OPTION EmailHost=YYYY.XXX.org;
OPTION EmailPort=25;
IMHO, you typically use email if you want to let others know about a problem. If it is only for you why not just create an exception or tracking report in a folder where you can just go and view it? Sending an email sounds like an unnecessary complication.
Not that I disagree entirely with you, but for some processes, if they're critical enough -- or if they so seldom have problems that you might forget to check such a folder, I actually send an email to my smart phone which pops up as a text message. That way, I can jump on a critical problem or get notified of something that so rarely occurs that I might otherwise miss it.
Each to his or her own, I suppose, but that's been helpful to me, particularly the critical issues.
Jim
First of all, I think email is fine to use. Everyone likes their own means of communication and email works well. So does SMS and other means. Email/SMS show up while you are anywhere which is nice.
That out of the way, when I send email I use a service. Our solution involves our own services but it is easy to use SMS or email services (ex. MailChimp using proc http. Look here: SAS Help Center: Syntax: PROC HTTP PROC HTTP Statement
You will probably be using a POST command so follow that.
Also, there are other services other than MailChimp. Pick whichever one works for you and do a REST call. REST makes everything easy w/o having to reinvent the world. There will also be REST calls for SMS.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.