DATA Step, Macro, Functions and more

Covert date text to number text

Reply
Contributor
Posts: 26

Covert date text to number text

Hello - 

 

I currently have 2016-01-01 in my data.. its format is text,20. 

 

I want to join it with another table that i have and its format is 01JAN2016 00:00:00

 

How do I first convert the text DATE into number DATE and then in the correct format to join on this ^

 

I initially did Input(A.int_date, datetime20.) but it made all the rows blank. 

 

Any ideas?


Thanks!

Respected Advisor
Posts: 4,651

Re: Covert date text to number text

[ Edited ]

Build a SAS datetime value with function DHMS

 

dt = dhms(input(A.int_date, yymmdd10.), 0, 0, 0);

format dt datetime20.;

PG
Contributor
Posts: 26

Re: Covert date text to number text

I forgot to mention Im using PROC SQL

So i need something that is supported by that.
Super User
Posts: 10,500

Re: Covert date text to number text

dhms(input(A.int_date, yymmdd10.), 0, 0, 0) is supported by SAS Proc SQL.

You can us the value in a where clause as: Where dhms(input(A.int_date, yymmdd10.), 0, 0, 0) > <some datetime value>

or

join on dhms(input(A.int_date, yymmdd10.), 0, 0, 0) = b.datetimevariablename

Ask a Question
Discussion stats
  • 3 replies
  • 228 views
  • 0 likes
  • 3 in conversation