10-23-2015 02:14 AM
I have a problem with a 'Date'.
I have a date value in this format DDMMMYYYY:00:00:00. Now, during some operation, it gets converted to a number (10 digit) while sending it to a character field with some other numeric and character values. I would like to convert it back to a date value, else it does not make sense for presentation purpose.
I have tried:
format x Date9.;
It does not work. Also, will be possible to keep the date at the same character field, after the conversion? Reason is, the character field is supposed to hold the values of multiple character, numeric and date values.
Thank you all in advance.
10-23-2015 02:49 AM
Not understand how and why you do the different conversions.
But the best would be to store the value as a SAS date (dateime) value, then you can use formats to display it almost in any format that you like, without having to do conversions.
Assuming that you have 0:00:00 as a time in your example, this is really a date value, right?
The simplest is to do a substr() and input() using date9. informat.
10-23-2015 03:32 AM
I think that your datetime variable is SA datetime variable if it is ten digit long number, number of seconds after 01JAN1960 00:00. You just have to use proper format to display it. You can take the day out with datepart function as separate variable.
10-23-2015 04:12 AM
Out of interest, is there a reason that you do not use ISO dates, i.e. YYYYMMDDTHH:MMS...? I would have thought that would be better for a text field and more standard. It can then be used with the E8601 format, and you can keep date, time, or datetime as a numeric field. This is what we do in my industry, numeric date, time, and character ISO date.
10-23-2015 09:43 AM
10-23-2015 09:48 AM
Lets backtrack a bit, the post doesn't make much sense, you can't take a max of character data. Perhaps start by posting some example test data (a couple of obs) in the form of a datastep, and what you want the output to look like.
10-23-2015 10:41 AM
Here's some code that gets you back and forth between char and date formats:
format date datetime18.;
date = '23OCT2015:10:40:30'dt;
date_char = input(put(date,datetime18.),$18.);
format date date9.;
date = input(put(date_char,$18.),date9.);