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:
data want;
set have;
x=input(strip(value), datetime18.);
format x Date9.;
run;
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.
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.
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.
Out of interest, is there a reason that you do not use ISO dates, i.e. YYYYMMDDTHH:MM:SS...? 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.
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.
Here's some code that gets you back and forth between char and date formats:
data have;
format date datetime18.;
date = '23OCT2015:10:40:30'dt;
date_char = input(put(date,datetime18.),$18.);
run;
data want;
set have(keep=date_char);
format date date9.;
date = input(put(date_char,$18.),date9.);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.