Help using Base SAS procedures

SAS Email - Insert a date in the subject line

Accepted Solution Solved
Reply
Regular Contributor
Posts: 233
Accepted Solution

SAS Email - Insert a date in the subject line


I need to insert today's date 09/18/2014 in the email subject line. The email subject line would be "Reports for 09/18/2014". Any help is greatly appreciated.


Accepted Solutions
Solution
‎09-18-2014 12:23 PM
Contributor
Posts: 21

Re: SAS Email - Insert a date in the subject line

You can use a %let statement to create the date and then call it within your subject line.

FILENAME MailBox EMAIL ATTACH='TestFile';

%LET DATE = %sysfunc( putn( %sysfunc( date() ), MMDDYY10. ));

%Put &DATE;

DATA _NULL_;

  FILE Mailbox TO=('Someone@somwhere.com')

  SUBJECT = "Test&Date" ;

  PUT "Test Test Test";

RUN;

View solution in original post


All Replies
Frequent Learner
Posts: 1

Re: SAS Email - Insert a date in the subject line

Would something like below work?

data _null_;

call symputx("today",put(today(),mmddyy10.));

run;

%put today=&today;

options emailsys=smtp emailhost=youremailhost emailport=xx;

filename mailbox email "hima@xyz.com";

data _null_;

   file MailBox TO=("hima@xyz.com" )

CC=("XXX@xyz.com")

FROM='hima@xyz.com'

REPLYTO='hima@xyz.com'

SUBJECT="Reports for &today.";

put "Attached are today's reports";

put "Reply with any questions.";

run;

Solution
‎09-18-2014 12:23 PM
Contributor
Posts: 21

Re: SAS Email - Insert a date in the subject line

You can use a %let statement to create the date and then call it within your subject line.

FILENAME MailBox EMAIL ATTACH='TestFile';

%LET DATE = %sysfunc( putn( %sysfunc( date() ), MMDDYY10. ));

%Put &DATE;

DATA _NULL_;

  FILE Mailbox TO=('Someone@somwhere.com')

  SUBJECT = "Test&Date" ;

  PUT "Test Test Test";

RUN;

Super Contributor
Posts: 291

Re: SAS Email - Insert a date in the subject line

How about SUBJECT = "Report for &sysdate"?

Needs no other code, and avoids the problem of MMDDYY and DDMMYY confusion for situations when both MM and DD are <= 12 - the first 12 days of every month.

Bill

Respected Advisor
Posts: 3,156

Re: SAS Email - Insert a date in the subject line

I see two issues:

1)Small issue: the format.Solutions involving putn or put go extra miles just to get the format OP asked for.

2)Big issue: &sysdate is the date when your current SAS process fired up, which is not necessarily 'today' , per se.

Regards,

Haikuo

Super Contributor
Posts: 291

Re: SAS Email - Insert a date in the subject line

As we move to more and more global applications, the OP request may need to take second place to a format that can't be confused.

You are correct about the big issue - although it's not a problem for batch processing, which is what I had in mind.

Respected Advisor
Posts: 3,156

Re: SAS Email - Insert a date in the subject line

"although it's not a problem for batch processing, which is what I had in mind."

Batch or not, 'sysdate' is still the date when you start up your current batch. It remains the same issue (not being 'today') if your batch runs across the mid-night or as long as the date of the 'email' is not the same as the date when you start your SAS session (batch or interactive).

my2cents,

Haikuo

Occasional Contributor
Posts: 15

Re: SAS Email - Insert a date in the subject line

This is what I'm using:

data age;

    set members14to15;

    format today DATETIME22.3;

    today = today();

    year = year(today());

    age = year - year(datepart(birth_date));

    if birth_date > today then age=age-1;   

run;

I need the age of a member based on their birth date. The problem is - if a person has NOT had their birthday this year, it's still calculating as if they had. Does this help?

Occasional Contributor
Posts: 15

Re: SAS Email - Insert a date in the subject line

Posted in reply to emmytheduck

Didn't mean to post here. Sorry.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 1381 views
  • 4 likes
  • 6 in conversation