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

Hi

 

I'm experiencing weird SAS behavior:

 

data a;
/*    uncomment for input to work in the next data step*/
/*    length date1 $20; */
    date1 = '2015-10-26T23:59';
    date2 = '2015-10-26';
run;

data b;
    set a;
    not_related = trim(left(strip(date2)))||'T23:59';
    dt = input(date1, e8601dt.);
run;

the second datastep produces a note that input has invalid argument. However, if in first datastep I set date1 length to $20, then the second step has no problem to run and input date/time.

 

Tested on SAS 9.3 TS Level 1M2 X64_ES08R2.

 

Anyone else seen this before?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Its a known bug since SAS 9.2. What happening here is width of E8601DT must be 19 but the width
of value is only 16, so extra 3 characters are taken from the followed values.

Capture.PNG

 

 

Here in the example it is trying to take the values '201' as seconds i.e attempting to takes
values as ":ss". As 201 is not in the format as ":ss" it throwed an error as invalid argument.

 

This issue has been fixed in SAS 9.4

 

FYI: http://support.sas.com/kb/43/743.html

Thanks,
Suryakiran

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I don't get this, using 9.4:

299 data a;
300 /* uncomment for input to work in the next data step*/
301 /* length date1 $20; */
302 date1 = '2015-10-26T23:59';
303 date2 = '2015-10-26';
304 run;

NOTE: The data set WORK.A has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


305
306 data b;
307 set a;
308 not_related = trim(left(strip(date2)))||'T23:59';
309 dt = input(date1, e8601dt.);
310 run;

NOTE: There were 1 observations read from the data set WORK.A.
NOTE: The data set WORK.B has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.00 seconds

 

What does your log look like?

TD
Calcite | Level 5 TD
Calcite | Level 5
1    data a;
2    /*    uncomment for input to work in the next data step*/
3    /*    length date1 $20; */
4        date1 = '2015-10-26T23:59';
5        date2 = '2015-10-26';
6    run;

NOTE: The data set WORK.A has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
7
8    data b;
9        set a;
10       dt = input(date1, e8601dt.);
11   run;

NOTE: Invalid argument to function INPUT at line 10 column 10.
date1=2015-10-26T23:59 date2=2015-10-26 dt=. _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 10:10
NOTE: There were 1 observations read from the data set WORK.A.
NOTE: The data set WORK.B has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, I don't have 9.3 to hand and can't find a page on changes, but it may be that in 9.4 they relaxed the requirements on the string.  Does adding the seconds part change this, I remember I always used to have to add ":00" to the end to get the format to work for me.

TD
Calcite | Level 5 TD
Calcite | Level 5

I think it's a SAS 9.3 bug. Adding seconds ':00' works the same way as increasing date1 length to $19 - input is performed correctly (as expected). Must be some kind of memory optimisation bug - because changing value of date2 to '2' also lets to input date1 without an error.

 

Just noticed, that if I initialize date2 before date1, the input works as expected.

 

Thanks

 

ballardw
Super User

When I read the documentation for E8601dt informat is says default length is 19 and minimum length is 19, ie. E8601dt19. max length 26.

When you use

date1 = '2015-10-26T23:59'

the length of date1 is 16, which is too short generating the error.

This doesn't generate the error.

data a;
/*    uncomment for input to work in the next data step*/
/*    length date1 $20; */
    date1 = '2015-10-26T23:59:00';
    date2 = '2015-10-26';
run;

data b;
    set a;
    not_related = trim(left(strip(date2)))||'T23:59';
    dt = input(date1, e8601dt.);
run;

Neither does:

 

data a;
/*    uncomment for input to work in the next data step*/
/*    length date1 $20; */
    date1 = '2015-10-26T23:59   ';
    date2 = '2015-10-26';
run;

data b;
    set a;
    not_related = trim(left(strip(date2)))||'T23:59';
    dt = input(date1, e8601dt.);
run;

The Input and informat are apparently checking on the length propery of the variable not the number of assigned characters.

 

TD
Calcite | Level 5 TD
Calcite | Level 5

does not seem a consistent check: there's no problem to input a value from variable with length of $16 when the date2 is initialized first in the first data step.

ballardw
Super User

This is definitely odd:

data a;
    length date1 date2 $ 16 ; 
    date1 = '2015-10-26T23:59:00';
    date2 = '2015-10-26T23:59';
run;

data b;
    set a;
    dt1 = input(date1, e8601dt.);
    dt2 = input(date2, e8601dt.);
run;

It may be time to contact Tech support as this particular bit might be an actual bug.

 

But I would suggest if possible sticking to declaring any variable like this with a length at least 19 and not relying on implied length assignments. Explicit lengths are better programming practice.

SuryaKiran
Meteorite | Level 14

Its a known bug since SAS 9.2. What happening here is width of E8601DT must be 19 but the width
of value is only 16, so extra 3 characters are taken from the followed values.

Capture.PNG

 

 

Here in the example it is trying to take the values '201' as seconds i.e attempting to takes
values as ":ss". As 201 is not in the format as ":ss" it throwed an error as invalid argument.

 

This issue has been fixed in SAS 9.4

 

FYI: http://support.sas.com/kb/43/743.html

Thanks,
Suryakiran

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1456 views
  • 0 likes
  • 4 in conversation