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

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@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

--
Paige Miller
Tom
Super User Tom
Super User

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;

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!
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
  • 3322 views
  • 6 likes
  • 4 in conversation