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

Hello,

 

I'm trying to import a csv file that looks like this:

Capture.PNG

I want to separate date and time into two variables, but I can't find the correct informat/format to even import it as date/time together. I know how to separate the date and time parts once I can get the initial date/time imported into my dataset.

 

Thank You.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
I would suggest separating it after the fact. Assuming it gets imported as a datetime, you can then use the DATEPART() and TIMEPART() function.

You can do it in the same step as you import your data though, assuming you're using a data step.

data want;
infile 'path to csv file' dsd truncover;
informat date_time anydtdtm. unit $10. Value 12.3;
input date_time unit value;
date=datepart(date_time);
time=timepart(date_time);

format date_time datetime22. date date9. time time8.;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User
I would suggest separating it after the fact. Assuming it gets imported as a datetime, you can then use the DATEPART() and TIMEPART() function.

You can do it in the same step as you import your data though, assuming you're using a data step.

data want;
infile 'path to csv file' dsd truncover;
informat date_time anydtdtm. unit $10. Value 12.3;
input date_time unit value;
date=datepart(date_time);
time=timepart(date_time);

format date_time datetime22. date date9. time time8.;
run;
lburda
Calcite | Level 5
Thank you, this worked perfectly!

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1244 views
  • 0 likes
  • 2 in conversation