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.
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';
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
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?
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';
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.