Hi all,
I want to ask a question regarding input DATETIME to SAS. I am using data from Thomson Reuters Tick History (TRTH). In Version1 of TRTH, data had two separate columns for Date and Time. However, in the second version, TRTH changes that structure and now they provide DATETIME column.
I want to input csv data to SAS by using codes (not manual (File-Import Data)). When I use data from version 1, I employed the format (and informat) Date11. for Date and time18.3 for time. For example, I run the following codes and it works very well:
data test;
infile _____________
" delimiter = _______________;
informat Date_G_ DATE11. ;
informat Time_G_ time18.3 ;
format Date_G_ DATE11. ;
format Time_G_ time18.3 ;
input
Date_G_
Time_G_; run;
However, now, I need to use format and informat for DATETIME column. In csv format, it looks like that :
2018-04-06T15:45:00.377379752Z
I did some search, however cannot get result. I would appreciate it if you could help me regarding that.
Thanks in advance.
Best
Looks like an ISO date with timezone offset. You can find all the informats here:
Maybe n8601 or anydtdtm will work. Just need to try them out and see if it matches what you expect.
Looks like an ISO date with timezone offset. You can find all the informats here:
Maybe n8601 or anydtdtm will work. Just need to try them out and see if it matches what you expect.
One more question:
How to apply datepart function to n8601 format?
datepart() gives '.' value.
Should work fine, can you give a simple example in the form of a datastep?
Did you mean the whole code?
I run the following codes:
data want;
set have;
Date=datepart(date_time);
run;
Just an example, like the one below. The n8601 informat creates a character, so the numeric datepart() function doesn't work, sorry, not used that informat before. This does work:
data want; input a $n8601e.; b=mdy(input(substr(a,5,1),best.),input(substr(a,6,2),best.),input(substr(a,1,4),best.)); format b date9.; datalines; 2018-04-06T15:45:00.377379752Z ; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.