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

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Khaladdin
Quartz | Level 8
$N8601Ew.d works well. Many thanks for that.
Khaladdin
Quartz | Level 8

One more question:

 

How to apply datepart function to n8601 format?

datepart() gives '.' value.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Khaladdin
Quartz | Level 8

Did you mean the whole code?

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

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Khaladdin
Quartz | Level 8
Great, thanks

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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