DATA Step, Macro, Functions and more

how to compare a charactor datetime with a numeric datetime.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

how to compare a charactor datetime with a numeric datetime.

I have two variables in this dateset.

 

column A                               column B

2016-12-09T09:45                 22NOV2016:00:50:07

 

column A is charactor variable. column B is numeric.

Each variable I have about 200 obs.

I need to not only consider the date, but also the time.

For some obs, that have same date, so I also need to compare time.


Accepted Solutions
Solution
‎06-28-2017 09:11 AM
Super User
Posts: 7,866

Re: how to compare a charactor datetime with a numeric datetime.

There are ISO-formats for this type of date and datetime notation:

data have;
input col_a :$16. col_b :datetime19.;
format col_b datetime19.;
cards;
2016-12-09T09:45 22NOV2016:00:50:07
;
run;

data want;
set have;
col_a_num = input(col_a,e8601dt19.);
format col_a_num datetime19.;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎06-28-2017 09:11 AM
Super User
Posts: 7,866

Re: how to compare a charactor datetime with a numeric datetime.

There are ISO-formats for this type of date and datetime notation:

data have;
input col_a :$16. col_b :datetime19.;
format col_b datetime19.;
cards;
2016-12-09T09:45 22NOV2016:00:50:07
;
run;

data want;
set have;
col_a_num = input(col_a,e8601dt19.);
format col_a_num datetime19.;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 5

Re: how to compare a charactor datetime with a numeric datetime.

Posted in reply to KurtBremser


Thank you so much! It is working. I was try to find the right input format for a long time.



Thank you. Great answer!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 104 views
  • 1 like
  • 2 in conversation