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

Had a few surprises using the b8601dj informat to read date-time values YYYYMMDDHHMMSS.

 

If the time portion is 250000 it returns a null value, and does NOT throw an error.  This is different than the datetime informat, which would treat it as 0100 on the next day:

 

1    data _null_ ;
2      datetime=input('01JAN1960:25:00:00',datetime18.) ;
3      b8601dj =input('19600101250000'    ,b8601dj14.) ;
4
5      put datetime= b8601dj= ;
6      format  datetime b8601dj datetime19. ;
7    run ;

datetime=02JAN1960:01:00:00 b8601dj=.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

I'm okay with 250000 being treated as invalid, but I would expect an error in the log.

 

Also surprising, even letters in the value will not cause an error message, as long as the first ten characters are numeric:

 

8    data _null_ ;
9      b8601dj=input('1960010199QQQQ',b8601dj14.) ;
10     put b8601dj= ;
11   run ;

b8601dj=.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

If I add one more letter, it will finally throw an error:

12   data _null_ ;
13     b8601dj=input('196001019QQQQQ',b8601dj14.) ;
14     put b8601dj= ;
15   run ;

ERROR: Invalid argument to function INPUT at line 13 column 11.
b8601dj=. _ERROR_=1 _N_=1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

Is this surprising behavior?  Seems like it's worth documenting.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Rick Wicklin presents Ten Tips for Effective Statistical Graphics (with SAS code) on Wednesday March 26.
Register now at https://www.basug.org/events.
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Quentin,

 

I can replicate both your examples and Patrick's (which is different) with the same 9.4M5 release as his. To get your "ERROR: Invalid argument ..." message (and the subsequent error-like behavior) I need to use the (undocumented) dsoptions=note2err system option, though.

 

Whenever the result was a missing value which was not accompanied by an "Invalid argument" message the result did not change when I set

options invaliddata='X';

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

It does write a Note an it sets the automatic variable _ERROR_ to 1 in my SAS version (SYSVLONG 9.04.01M5P091317) so you could add a check on  _ERROR_ or the resulting variable being missing.

28         data _null_ ;
29           b8601dj=input('196001019QQQQ',b8601dj14.) ;
30           put b8601dj= ;
31         run ;

NOTE: Invalid argument to function INPUT at line 29 column 11.
b8601dj=.
b8601dj=. _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 29:11  
Quentin
Super User

Thanks @Patrick. I’m on 9.4M4, maybe it’s fixed in M5.

What do you get from:

b8601dj =input('19600101250000' ,b8601dj14.) ;


Does it return null or does it return 2 Jan 1:00am? If it returns null, does it throw the invalid note?

 

What do you get from:

b8601dj=input('1960010199QQQQ',b8601dj14.) ;

 

I assume it returns null.  Does it throw the invalid note?

The Boston Area SAS Users Group is hosting free webinars!
Next up: Rick Wicklin presents Ten Tips for Effective Statistical Graphics (with SAS code) on Wednesday March 26.
Register now at https://www.basug.org/events.
FreelanceReinh
Jade | Level 19

Hi @Quentin,

 

I can replicate both your examples and Patrick's (which is different) with the same 9.4M5 release as his. To get your "ERROR: Invalid argument ..." message (and the subsequent error-like behavior) I need to use the (undocumented) dsoptions=note2err system option, though.

 

Whenever the result was a missing value which was not accompanied by an "Invalid argument" message the result did not change when I set

options invaliddata='X';
Quentin
Super User
Thanks @FreelanceReinhard. That’s enough confirmation for me to consider this a bug. I’ll send it in.

You’re right, I have Note2Err turned on, I always forget that.

I didn’t know about the invaliddata option. So thanks for mentioning that as well!
The Boston Area SAS Users Group is hosting free webinars!
Next up: Rick Wicklin presents Ten Tips for Effective Statistical Graphics (with SAS code) on Wednesday March 26.
Register now at https://www.basug.org/events.
Quentin
Super User

I sent it in to tech support, and they confirmed it's a bug that b8601dj informat is not throwing the INVALID DATA note as it should. They said they will file a defect.

 

Thanks all.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Rick Wicklin presents Ten Tips for Effective Statistical Graphics (with SAS code) on Wednesday March 26.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1275 views
  • 2 likes
  • 3 in conversation