- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear Group,
I'm trying to work with a big dataset (>1 million lines) file where I have dateandtime data combined in DATETIME16. format.
These datetime are corresponding to a variable named Creation_date. I am not used with that format.
I want to split the variable Creation_date.in date_created and time_created (the 1st variable would be the date dd/mm/yyyy and the second would be the time).
I've found some way to do it after manually importing the data using CARDS but this is not feasible with a large dataset.
thank so much!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It's not clear from your post if your variable is a character variable that looks like DATETIME16., or if it's already a SAS datetime variable that has a DATETIME16. format applied.
If it's the former, you can use the INPUT function to transform it to a SAS datetime variable, something like the following:
GoodVar = input(BadVar, anydtdtm16.);
Once you have it as a datetime variable, there are a number of options. Easiest is to leave it as a datetime variable, but just use formats to display the date and time. Alternately, the DATEPART and TIMEPART functions will divide the datetime variable.
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SAS has functions that accomplish this simply:
data want;
set have;
time_created= timepart(creation_date);
date_created = datepart(creation_date);
format date_created ddmmyys10.;
run;
You might also select a format for the TIME_CREATED variable. You have choices to make here, so this is a good place to start:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It's not clear from your post if your variable is a character variable that looks like DATETIME16., or if it's already a SAS datetime variable that has a DATETIME16. format applied.
If it's the former, you can use the INPUT function to transform it to a SAS datetime variable, something like the following:
GoodVar = input(BadVar, anydtdtm16.);
Once you have it as a datetime variable, there are a number of options. Easiest is to leave it as a datetime variable, but just use formats to display the date and time. Alternately, the DATEPART and TIMEPART functions will divide the datetime variable.
Tom