BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SBuc
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

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

 

 

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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:

https://documentation.sas.com/?docsetId=leforinforref&docsetTarget=p0b2xn5ovzhtjnn1db5g1gg64yhf.htm&...

TomKari
Onyx | Level 15

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

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to connect to databases in SAS Viya

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.

Discussion stats
  • 2 replies
  • 5658 views
  • 0 likes
  • 3 in conversation