DATETIME_FORMAT

Accepted Solution Solved
Reply
Contributor
Posts: 64
Accepted Solution

DATETIME_FORMAT

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

 

 


Accepted Solutions
Solution
‎04-27-2018 06:15 AM
Super User
Super User
Posts: 9,599

Re: DATETIME_FORMAT

Posted in reply to Khaladdin

Looks like an ISO date with timezone offset.  You can find all the informats here:

http://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n0verk17pchh...

 

Maybe n8601 or anydtdtm will work.  Just need to try them out and see if it matches what you expect.

View solution in original post


All Replies
Solution
‎04-27-2018 06:15 AM
Super User
Super User
Posts: 9,599

Re: DATETIME_FORMAT

Posted in reply to Khaladdin

Looks like an ISO date with timezone offset.  You can find all the informats here:

http://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n0verk17pchh...

 

Maybe n8601 or anydtdtm will work.  Just need to try them out and see if it matches what you expect.

Contributor
Posts: 64

Re: DATETIME_FORMAT

$N8601Ew.d works well. Many thanks for that.
Contributor
Posts: 64

Re: DATETIME_FORMAT

One more question:

 

How to apply datepart function to n8601 format?

datepart() gives '.' value.

Super User
Super User
Posts: 9,599

Re: DATETIME_FORMAT

Posted in reply to Khaladdin

Should work fine, can you give a simple example in the form of a datastep?

Contributor
Posts: 64

Re: DATETIME_FORMAT

Did you mean the whole code?

I run the following codes:
data want;
set have;
Date=datepart(date_time);

run;

Super User
Super User
Posts: 9,599

Re: DATETIME_FORMAT

Posted in reply to Khaladdin

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;
Contributor
Posts: 64

Re: DATETIME_FORMAT

Great, thanks
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 148 views
  • 2 likes
  • 2 in conversation