I'm having difficulty understanding why you want todays date in the subject
line. Surely it is implicit in the send date of the email?
Since a lot of reporting happens for data collected on days other than
today, such as 1am processes reporting yesterdays processes, it seems to me
that what you need is a subject that holds a date taken from the data that
represents the latest transaction reported.
Suppose you have a table called REPORTME which holds transactions with
DateTimes in TRANSDATE and you are reporting these to your readers.
A piece of SQL like the following untested code will capture the last
TRANSDATE into a macro variable:
Proc Sql _Method STimer;
Select Put( Max( TRANSDATE), DateTime9.)
Now when you define your subject in your filename statement you can resolve
the macro symbol into the subject declaration as follows:
Subject = "Error report for transactions to &MLastDate.."
By using a DateTime format you can include the time of day by extending the
length of the format. If you don't like that format, you can apply another
one, being careful that the data types match. It might be obvious, but a
common mistake is to use a date format for a DateTime column, and in this
case you need to use the DatePart() function first to extract the date from
There are some people who don't like macros, or have trouble using them. So
here is an alternative solution that does not use a macro symbol, but is
performed at the expense of some other assumptions about the data.
To run this, we will use an email directive in our output file. We will
exploit the behaviour of the directives, which is that the last instance of
the directive will take precedence. We need to have our data in DateTime
order for this to work. We also need to have the report column (TRANSDATE)
in the correct form for reporting. You can't insert a function at this
point, although clever use of formats (such as using a length 9 for
DateTime) will let you extract a date part from a datetime value.
Within your email data step, add the following statement.
Put "!em_subject! Error report for transactions to " TRANSDATE DateTime9.;
The subject will be changed for each record read from the input table, but
you will only see the last value. I assume that since it is an email, you
aren't spamming people with 10,000 line emails, so there is little need to
worry about a statement being executed needlessly 9999 times. However, if
you are concerned, then use an "END" flag on the input data step and make
the Put statement conditional.
Be warned that this statement must either be used in isolation as written,
or if the code is embedded within other message lines put to the email, then
you must precede and terminate the directive with a new line marker "/".
Otherwise you will possibly have a scrambled subject line, or your message
will contain a strange string "!em_subject!"
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of Bhag
Sent: Thursday, 26 July 2007 3:39 AM
Subject: Display Date in the subject line in a SAS generated email -
Please some one let me know how could I display date on the subject
line along with other details,
eg: Subject: Error report for 07-25-2007
I am trying to send a SAS genearted email with subject line having