My ultimate goal is to split the date and time into separate columns in the dataset attached below, please kindly help me out.
If you have an actual SAS datetime value (can't tell from a CSV as it is not a SAS dataset yet) the function DATEPART returns the date portion and the function TIMEPART returns the time portion such as:
data want; set have; datevariable = datepart(datetimevariable); timevariable = timepart(datetimevariable); format datevariable date9. timevariable time8.; run;
Pick appropriate date format, your choice.
Thanks for the quick reply, but please how do I read the file correctly into sas before going ahead to split it?
filename x 'c:\temp\SCL.csv' encoding='utf8' termstr=crlf;
proc import datafile=x out=have dbms=csv replace;
guessingrows=max;
run;
data want;
set have;
datevariable = datepart(Date_Time);
timevariable = timepart(Date_Time);
format datevariable date9. timevariable time8.;
run;
Just read the Date-Time column as a character string.
filename csv temp;
options parmcards=csv;
parmcards;
#RIC,Domain,Date-Time,Type,Price,Volume,Bid Price,Ask Price
0DZC.L,Market Price,2019-12-02T07:51:08.550270041Z,Quote,,,21.64,
0DZC.L,Market Price,2019-12-02T07:51:08.551068323Z,Quote,,,21.64,22.74
0DZC.L,Market Price,2019-12-02T08:11:47.326609096Z,Quote,,,21.4,22.74
0DZC.L,Market Price,2019-12-02T08:11:47.327322633Z,Quote,,,21.4,22.48
;
data have;
length ric $10 domain $20 datetime $32 date time 8 type $10 price volume bid ask 8;
infile csv dsd firstobs=2 truncover ;
format date yymmdd10. time time15.6 ;
input ric domain datetime type price volume bid ask;
date = input(datetime,yymmdd10.);
time = input(scan(datetime,2,'TZ'),time20.);
run;
Results
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.