12-18-2015 06:40 AM
I'm trying to convert variable from character to DATETIME. format. When I use the following code the latest six digits were 0 while they should be "860184" . What should I do to see right result. Also I would like to ask you when I try to overwrite "Date" variable I got the value as "0" or missing so I assigned the value in new variable then I dropped the variable and changed the new ariable name as old variable name. Is it possible to overwrite the variable without assign the variables value to new variable.
DATA HAVE(Drop=Date Rename=(Date2=Date)); Date="1960-01-01-00.00.00.860184"; /*Date=input(Date,anydtdtm.);*/ Date2=input(Date,anydtdtm.); FORMAT Date2 datetime27.6; RUN;
12-18-2015 07:08 AM
Well, I don't recognise that date time format. You get a 0 because the date and time given is the start point from where SAS calculates date values. Remember under the hood, SAS stores dates as number of days since 01JAN1960, and datetimes and number of seconds since 01JAN1960 00:00, so unformated that date is 0, 01jan would be 1 ...
As for the other part, I would recommen changing whatever that format of date time is over to ISO standard datetime:
12-18-2015 07:19 AM - edited 12-18-2015 07:29 AM
Well, when I try to convert to numeric variable it brings 0 I think it is related the date(1960) which I wrote in "Date" variable. But when I overwrite the variable as Datetime. format it brings missing value. What is the reason for that ??? Also, I couldn't understand why last 6 digits were zero even I've already put the value "860184" in the "Date" variable when I assign the value in new variable as Datetime.
12-18-2015 08:37 AM
Well, the date conversion is pretty straightforward. You assign date to be a character:
Then you try to put a number - that date is 0 numerically - into the character variable (i.e. implicit conversion).
So date becomes the numeric value of the date you gave, which is "0". 02 Jan would be "1".
12-18-2015 08:56 AM
Okay, lets think about value of "Date" is ->
and I take many datas from Excel or another environment as Datetime27.6 format. I mean the data which is located at Excel equal to Datetime27.6 format in SAS. When I Import these datas they come as Character type and I try to change the datas from Character to Datetime27.6 format but when I try it, it becomes as
but actual datas' last 6 digit include
so why I can't see the actual values and how can I fix it, how I can see whole of the actual value ???
12-18-2015 10:50 AM
You aren't importing the data correctly. I'm not sure what format you'll need to get your data in, a variant on E8601DT I imagine, or may need to format your date to match a present format....or create your own informat.
data example; length date_char $30.; date_char="2000-12-12T00:00:00.860184"; date_num_raw=input(date_char, e8601dt26.6); date_num_fmt=date_num_raw; format date_num_fmt datetime27.6 date_num_raw 26.6; run;
Obs date_char date_num_raw date_num_fmt 1 2000-12-12T00:00:00.860184 2000-12-12T00:00:00.860184 12DEC2000:00:00:00.860184
12-18-2015 03:12 PM
You can use the B8601DJ20.6 informat after removing the punctuation marks:
data have(drop=date rename=(date2=date)); date="2000-12-12-00.00.00.860184"; date2=input(compress(date, '-.'), b8601dj20.6); format date2 datetime27.6; run;
Instead of listing the punctuation marks explicitly in the second argument of the COMPRESS function, you can use the 'p' modifier to remove any punctuation marks (as well as blanks):