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=2019-10-31 00:00:00.447000;

 

This macro variable is having a value as character .i want it to convert to numeric 26

 

How can i do that ?

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @shubham1 ,

 

Something like this?

%let x= %sysfunc(inputn(2019-10-31 00:00:00.447000, ymddttm24.));
%put &x;

Result: 1888099200.447

View solution in original post

6 REPLIES 6
ed_sas_member
Meteorite | Level 14

Hi @shubham1 ,

 

Something like this?

%let x= %sysfunc(inputn(2019-10-31 00:00:00.447000, ymddttm24.));
%put &x;

Result: 1888099200.447

shubham1
Calcite | Level 5

I think output is wrong 

it is not coming as  2019-10-31 00:00:00.447000 .I want value to be numeric as 2019-10-31 00:00:00.447000 

ed_sas_member
Meteorite | Level 14

Hi @shubham1 

Macro variables are strings. They have no type (numeric / character).

All datetimes values are stored as numbers by SAS. If you want to use them for further calculation, you need to get those numbers.

 2019-10-31 00:00:00.447000 is not a valid numeric value.

PaigeMiller
Diamond | Level 26

@shubham1 wrote:

I think output is wrong 

it is not coming as  2019-10-31 00:00:00.447000 .I want value to be numeric as 2019-10-31 00:00:00.447000 


The result from @ed_sas_member of 1888099200.447 is correct. SAS considers date/times to be the number of seconds since midnight January 1, 1960, so that is how your date/time is represented in SAS. You can optionally format it so that it looks like an actual date/time to humans when they see it, but internally it needs to be 1888099200.447. You need to adjust your thinking so that you can use date/times properly in SAS. Any comparison of date/time values must be done numerically, rather than by a text string.

--
Paige Miller
shubham1
Calcite | Level 5

there was something wrong I did at my end sorry for that your solution is working 

ed_sas_member
Meteorite | Level 14
Hi @shubham1
Great to hear that!
Could you please mark the topic as answer so that it can be available to the whole community?

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
  • 6 replies
  • 5120 views
  • 2 likes
  • 3 in conversation