BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hima
Obsidian | Level 7


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.

1 ACCEPTED SOLUTION

Accepted Solutions
tuckeraw
Obsidian | Level 7

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

8 REPLIES 8
NijeB
Fluorite | Level 6

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;

tuckeraw
Obsidian | Level 7

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;

Bill
Quartz | Level 8

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

Haikuo
Onyx | Level 15

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

Bill
Quartz | Level 8

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.

Haikuo
Onyx | Level 15

"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

emmytheduck
Calcite | Level 5

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?

emmytheduck
Calcite | Level 5

Didn't mean to post here. Sorry.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 9413 views
  • 5 likes
  • 6 in conversation