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!
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
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:
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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.