I have below macro variable
%let x=01JAN2020:00:00:00:447;
i want it to convert to datetime25.6;
How can i do that ?
What do you plan to do with it? Are you going to us it to generate code? If so the way to specify a datetime constant in code is to quote a string that the DATETIME informat can read and suffix the quoted string with DT (for DateTime).
%let x=01JAN2020:00:00:00:447;
data want;
set have ;
where mydatetime_var < "&x"dt ;
run;
@shubham1 wrote:
I have below macro variable
%let x=01JAN2020:00:00:00:447;
i want it to convert to datetime25.6;
How can i do that ?
Macro variables do not have formats. They are text strings.
If you want to treat this macro variable as a SAS date/time value, so you can compare other date/time values to it to see if the other data/time value is before or after your macro variable &x, then it must be a number representing the number of seconds since midnight 1/1/60.
data _null_;
call symputx('x','01JAN2020:00:00:00.447'dt);
run;
%put &=x;
If you want to display it in a specific format, for example in a label or title, you can apply formatting then.
title "This is a title showing the datetime value of %sysfunc(putn(&x,datetime25.6))";
but if you are not planning to use this macro variable in titles or labels, do not format it. This is so important, I am going to say this three more times.
if you are not planning to use this macro variable in titles or labels, do not format it
if you are not planning to use this macro variable in titles or labels, do not format it
if you are not planning to use this macro variable in titles or labels, do not format it
if you are not planning to use this macro variable in titles or labels, do not format it
What do you plan to do with it? Are you going to us it to generate code? If so the way to specify a datetime constant in code is to quote a string that the DATETIME informat can read and suffix the quoted string with DT (for DateTime).
%let x=01JAN2020:00:00:00:447;
data want;
set have ;
where mydatetime_var < "&x"dt ;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.