In SAS, fields are either character of varying length, or numeric. No exceptions. Temporal values such as Date and Date/Time are stored as either the number of days or seconds since 1960 January 1st.
In order to convert from Date/Time to Date, and from Date to Date/Time, you could divide or multiply respectively by 86400 (the number of seconds in a day).
data _null_; d='29FEB1984'd; put d date.; dt=d*24*60*60; put dt datetime.; d=dt/24/60/60; put d date.; run;
But unless someone deals with dates every day, it might not be obvious to them by reading this code what those magic numbers are doing.
data _null_; d='29FEB1984'd; put d date.; dt=input(put( d ,date7.) || ':00:00:00', datetime.); put dt datetime.; d =input(substr(put(dt,datetime.),1,7),date7.); put d date.; run;
But I don’t consider this any better. It’s wordy. Functions are nested within functions. And you still have a magic number for the call to substr. Also, since it isn’t uncommon for SAS datasets to get into the billions of rows, this probably isn’t the fastest way to do it.
data _null_; d='29FEB1984'd; put d date.; dt=dhms(d,0,0,0); put dt datetime.; d =datepart(dt); put d date.; run;