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

I am referencing to a previous article in this link.

 

I'm trying to extract the modification datetime by using the Linux command stat.  Then, I convert it into ISO8601 format which then I convert it into SAS datetime value.  However, it does not appear to be working properly for me.

 

The stat command is issued as stat -c '%n %y' *.

The result is returned as:

copy_other_v2.sas 2019-05-17 10:42:28.697604000 -0400

copy_pgms_driver_21_cer.sas 2019-05-17 10:13:07.435587000 -0400

 

So, it's got blanks and missing the 'T' in the above DT string.  For the filename 'copy_other_v2.sas', I recoded them by adding a 'T' before the datetime part and removed the blank in the timezone offset.  So, the ISO8601 should look like this:

 

2019-05-17T10:42:28.697604000-0400

 

Right?  Then, since the length is 34, I tried to convert that string into SAS DT value using the E8601DZ34.

 

 

/*
ersaces01:/aepp/users/reidc/copyjobs$ stat -c '%n %y' *

copy_other_v2.sas 2019-05-17 10:42:28.697604000 -0400
copy_pgms_driver_21_cer.sas 2019-05-17 10:13:07.435587000 -0400
*/

/* Documentation used for this test:
   https://documentation.sas.com/?docsetId=leforinforref&docsetTarget=p1a0qt18rxydrkn1b0rtdfh2t8zs.htm&docsetVersion=9.4&locale=en
   SAS Communities article referenced:
   https://communities.sas.com/t5/General-SAS-Programming/Convert-ISO8601-string-to-datetime-format/m-p/421077#M52603
*/

data x;
   /* Recode original DT value into IS08601 DT    */
   /*   2019-05-17 10:42:28.697604000 -0400 becomes */
   /*   2019-05-17T10:42:28.697604000-0400          */
   x = '2019-05-17T10:42:28.697604000-0400';

   lenx = length(x);
   put lenx=;

   y = input(x, e8601dz34.);
   put y=;

   format y datetime20.;
run;

 

This is the error I kept getting:

 

 

 

 

241  /*
242  ersaces01:/aepp/users/reidc/copyjobs$ stat -c '%n %y' *
243
244  copy_other_v2.sas 2019-05-17 10:42:28.697604000 -0400
245  copy_pgms_driver_21_cer.sas 2019-05-17 10:13:07.435587000 -0400
246  */
247
248  /* Documentation used for this test:
249     https://documentation.sas.com/?docsetId=leforinforref&docsetTarget=p1a0qt18rxydrkn
249! 1b0rtdfh2t8zs.htm&docsetVersion=9.4&locale=en
250     SAS Communities article referenced:
251     https://communities.sas.com/t5/General-SAS-Programming/Convert-ISO8601-string-to-d
251! atetime-format/m-p/421077#M52603
252  */
253
254  data x;
255     /* Recode original DT value into IS08601 DT    */
256     /*   2019-05-17 10:42:28.697604000 -0400 becomes */
257     /*   2019-05-17T10:42:28.697604000-0400          */
258     x = '2019-05-17T10:42:28.697604000-0400';
259
260     lenx = length(x);
261     put lenx=;
262
263     y = input(x, e8601dz34.);
264     put y=;
265
266     format y datetime20.;
267  run;

lenx=34
NOTE: Invalid argument to function INPUT at line 263 column 8.
y=.
x=2019-05-17T10:42:28.697604000-0400 lenx=34 y=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results
      of the operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 263:8
NOTE: The data set WORK.X has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds

 

I expected the value of y to be in a numeric DT value formatted DATETIME20.  Can someone help me with this issue?

 

Thank you.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @CurtisER,

 

I think you just missed the colon in the offset: ...-04:00.

data x;
x = '2019-05-17T10:42:28.697604000-04:00';
y = input(x, e8601dz35.);
format y datetime20.;
run;

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @CurtisER,

 

I think you just missed the colon in the offset: ...-04:00.

data x;
x = '2019-05-17T10:42:28.697604000-04:00';
y = input(x, e8601dz35.);
format y datetime20.;
run;
CurtisER
Obsidian | Level 7

@FreelanceReinh wrote:

Hello @CurtisER,

 

I think you just missed the colon in the offset: ...-04:00.

data x;
x = '2019-05-17T10:42:28.697604000-04:00';
y = input(x, e8601dz35.);
format y datetime20.;
run;

 

Why, yes, I believe I did miss the colon in the offset!  Thanks for catching something this trivial, @FreelanceReinh.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1513 views
  • 1 like
  • 2 in conversation