Attention : This code requires administrator privileges.
The script begins by clearing the 'output' and 'log' DM (Display Manager) windows. It then defines three macros: 'startT' to capture the start date and time, 'endT' for the end date and time, and 'email' to format and send a notification email. The 'email' macro configures SMTP options and uses an EMAIL fileref to send the message. The script then calls 'startT' and 'endT', executes a simple DATA step 'Hello world!', and finally sends a notification email via the 'email' macro.
Data Analysis
Type : CREATION_INTERNE
The data manipulated in this script (dates, times, email messages) are dynamically generated or are literals. There is no reading of external data or persistent SAS datasets.
1 Code Block
Commandes DM
Explanation : These commands clear the content of the 'output' and 'log' Display Manager (DM) windows in the SAS environment.
Copied!
dm 'output;clear';
dm 'log;clear';
1
dm 'output;clear';
2
dm 'log;clear';
2 Code Block
MACRO STARTT
Explanation : This macro defines two macro variables, &startdate and &starttime, which contain the current formatted date and time at the moment of its execution. It uses a DATA _NULL_ step because no dataset is created.
Explanation : This macro configures system options for sending emails via SMTP, specifying the sender (EMAILID) and the server (EMAILHOST). It creates an 'mymail' fileref of type EMAIL, defines the recipient (TO) and the email subject using the 'dt' parameter passed to the macro. A DATA _NULL_ step is then used to write the body of the message to the file linked to 'mymail', including the previously captured start and end time information.
Copied!
%macro email(dt);
/* Set up the options for the email. */
OPTIONS EMAILSYS=smtp EMAILID="kfong @cornerstone.com"
EMAILHOST=CRDCEXCH10.cornerstone.com;
FILENAME mymail
EMAIL
TO = ("kfong @cornerstone.com")
SUBJECT="&dt. finished"
;
/* Send the email and define the message to send. */
DATA _NULL_;
FILE mymail;
PUT "Hello,";
PUT " ";
PUT "The code for &dt. has finished running.";
PUT "Start: &StartTime. &StartDate. ";
PUT "End: &EndTime. &EndDate. ";
RUN;
%mend;
/* Send the email and define the message to send. */
11
DATA _NULL_;
12
FILE mymail;
13
PUT "Hello,";
14
PUT " ";
15
PUT "The code for &dt. has finished running.";
16
PUT "Start: &StartTime. &StartDate. ";
17
PUT "End: &EndTime. &EndDate. ";
18
RUN;
19
%mend;
5 Code Block
Appel de macros
Explanation : These lines call the StartT and EndT macros to initialize the macro variables for the start and end date and time.
Copied!
%StartT;
%EndT;
1
%StartT;
2
%EndT;
6 Code Block
DATA STEP
Explanation : This simple DATA step writes the string "Hello world!" to the SAS log. It serves here as an example of code to be executed between the start and end timestamps.
Copied!
data _null_;
put "Hello world!";
run;
1
DATA _null_;
2
put "Hello world!";
3
RUN;
7 Code Block
Appel de macro
Explanation : This line calls the Email macro with 'test' as a parameter, which triggers the sending of the notification email with the subject 'test finished' and the execution time information.
Copied!
%Email(test);
1
%Email(test);
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Created by: Kevin Fong, Date Created: 2/4/14
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.