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

Hi,

 

I want to use the macro variable DATE defined below

%LET DATE = '29NOV2018'D; 

 

to create another macro variable that looks like this.

%LET DATETIME = '2018-11-29 00:00:00.0000000';

 

How can I achieve this?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
pradark1
Fluorite | Level 6
Here is a solution:

data _null_;
length datetime $ 30;
datetime = trim(put(&date,YYMMDD10.)) || " 00:00:00.0000000";
call symput("datetime",datetime);
run;

%put Datetime= &datetime.;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

Since a date is a count of days, and a datetime a count of seconds, you only need to multiply with 86400 wherever you need the datetime, or use the dhms() function.

Note that your wanted value is useless except for display.

Reeza
Super User

@pradark1 wrote:

Hi,

 

I want to use the macro variable DATE defined below

%LET DATE = '29NOV2018'D; 

 

to create another macro variable that looks like this.

%LET DATETIME = '2018-11-29 00:00:00.0000000';

 

How can I achieve this?

 

Thanks!


Use DHMS function. Note the second parameter in SYSFUNC is the format. The default will be a datetime that's numeric, to have is shown as indicated you need to apply a format, in this case I've used datetime. Note that applying a display format makes it more difficult to use in the future because you need quotes and dt at the end, whereas the numerical variable will be interpreted correctly. 

 

%let datetime = %sysfunc(dhms(&date., 0, 0, 0), datetime.);
%put &datetime.;

The 

pradark1
Fluorite | Level 6
Guys, I want the date to be displayed as a text string due to how it is used in my database. so being able to use the following format is important. I want the right hand side of the equation below to be another macro that converts to text like below.
%LET DATETIME = '2018-11-29 00:00:00.0000000';
pradark1
Fluorite | Level 6
Here is a solution:

data _null_;
length datetime $ 30;
datetime = trim(put(&date,YYMMDD10.)) || " 00:00:00.0000000";
call symput("datetime",datetime);
run;

%put Datetime= &datetime.;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 3992 views
  • 3 likes
  • 3 in conversation