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?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 6242 views
  • 2 likes
  • 3 in conversation