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

I'm runnint the following code to generate an email from sas. I'd like to put a date stamp with it. While running it I get the error 22-322 from PUT datetime(). What is the proper syntax? Thanks.

 

FILENAME outbox EMAIL ("xxx.xxx@xxx.com");

DATA _NULL_;
	FILE outbox
		TO="steve.rogers@ge.com"
		/*TO=("My.Boss@Delta.com" "My.Other.Boss@Delta.com")
		FROM=("Andrew.Hummel@Delta.com")*/
		SUBJECT=("Example of a SAS E-mail with Attachments" )
		/*ATTACH=("/sas_server/reports/Daily_Cancelled_Flight_Report.pdf"
		"/sas_server/reports/Daily_Delayed_Flight_Report.pdf");*/
		;
	PUT " ";
	PUT "Hello,";
	PUT " ";
	PUT datetime();
	/*PUT ("This is an update for ",datetime());*/
	PUT " ";
	PUT "Steve";
RUN;
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Datetime is a function to achieve the stamptime and assign it into a variable.

Having the variable assigned you need to define a format how to display it in your email.

 

Therefore do:

FILENAME outbox EMAIL ("xxx.xxx@xxx.com");

DATA _NULL_;
  dtime = datetime();      /* <<< line added */
	FILE outbox
		TO="steve.rogers@ge.com"
		/*TO=("My.Boss@Delta.com" "My.Other.Boss@Delta.com")
		FROM=("Andrew.Hummel@Delta.com")*/
		SUBJECT=("Example of a SAS E-mail with Attachments" )
		/*ATTACH=("/sas_server/reports/Daily_Cancelled_Flight_Report.pdf"
		"/sas_server/reports/Daily_Delayed_Flight_Report.pdf");*/
		;
	PUT " ";
	PUT "Hello,";
	PUT " ";
/*	PUT datetime(); */
	PUT  dtime datetime19.;   /* line was edited according to Tom's note */
	PUT " ";
	PUT "Steve";
RUN;

 

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

Datetime is a function to achieve the stamptime and assign it into a variable.

Having the variable assigned you need to define a format how to display it in your email.

 

Therefore do:

FILENAME outbox EMAIL ("xxx.xxx@xxx.com");

DATA _NULL_;
  dtime = datetime();      /* <<< line added */
	FILE outbox
		TO="steve.rogers@ge.com"
		/*TO=("My.Boss@Delta.com" "My.Other.Boss@Delta.com")
		FROM=("Andrew.Hummel@Delta.com")*/
		SUBJECT=("Example of a SAS E-mail with Attachments" )
		/*ATTACH=("/sas_server/reports/Daily_Cancelled_Flight_Report.pdf"
		"/sas_server/reports/Daily_Delayed_Flight_Report.pdf");*/
		;
	PUT " ";
	PUT "Hello,";
	PUT " ";
/*	PUT datetime(); */
	PUT  dtime datetime19.;   /* line was edited according to Tom's note */
	PUT " ";
	PUT "Steve";
RUN;

 

Tom
Super User Tom
Super User

Note there is a "feature" of the DATATIME  format that makes using DATETIME18. useless. Even though 9 character date plus 8 character time plus 1 character separator will fit in 18 characters, the format will NOT use 4 digit years if you set the width to 18. You need to use width of at least 19.

 

data _null_;
 dt=datetime();
 put dt= datetime18.;
 put dt= datetime19.;
run;

 

dt=27JUL17:10:40:17
dt=27JUL2017:10:40:17
capam
Pyrite | Level 9
Thanks for the simple solution.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3987 views
  • 0 likes
  • 3 in conversation