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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.