|
I came across some work-arounds in the Y2K area, that looked a bit
too heavy.
Recent postings in the "look-up table v formats" area reminded me of
strange behaviour around nested formats
leading to this small example
objective : ======>
display datetime values, with century, but
without showing seconds
solution : ======>
a user format SHORDT nesting datetime22.2
and truncating off the seconds by default
off the wall : answers to 1) when time 24:00:00 might appear
2) day and month are OK but year= ****
1 proc format;
2 value SHORdT (default=16)
3 /* w.=16.--> datetime. with century but no secs */
4
5 /* need to handle full range of values in a numeric variable */
6 . = ' .'
7
8 low - <'1jan1582 :00:00:00'dt = ' pre-Gregorian'
9
10 %sysfunc( sum(1,'31dec20000:23:59:59'dt)) - high = ' post SAS window'
/* have you a less-heavyweight way to generate this format range
starts with integer = the first day number too large for SAS ? */
11
12 other = [datetime22.2]
13 ;
NOTE: Format SHORDT has been output.
14 quit;
NOTE: The PROCEDURE FORMAT used 0.22 seconds.
15
16
17 %let putit= put / (d d d) ( 16.3 +2 datetime22.2 +2 shordt. );
/* I'm going to repeat this code a few times so I put it in a macro var*/
18
19
20 data testing;
21
22 d= .; &putit;
23 d='1jan1582:0:0'dt - .001; &putit;
24 /* .1 sec before 1Jan1582 */
25 d=d+.001; &putit;
26 d=datetime(); &putit;
27 d='31dec20000:23:59:59'dt; &putit;
28 put @60 'year= 20,000 !';
29 d='31dec20000:23:59:59.999'dt; &putit;
30 put @60 'secs= 59.999 !';
31 d=d+.001; &putit;
32 put @60 'year= 20,001 !';
33 run;
/* internal value <--------formatted with-------------->
16.3 datetime22.2 user fmt SHORDT.
. . .
-11928470400.001 ********************** pre-Gregorian
-11928470400.000 01JAN1582:00:00:00.00 01JAN1582:00:00
1227202710.180 20NOV1998:17:38:30.18 20NOV1998:17:38
569318630399.000 31DEC****:23:59:59.00 31DEC****:23:59
year= 20,000 !
569318630399.999 31DEC****:24:00:00.00 31DEC****:24:00
secs= 59.999 !
569318630400.000 ********************** post SAS window
year= 20,001 !
NOTE: The data set WORK.TESTING has 1 observations and 1 variables.
The main idea was to generate ddMMMyyyy:hh:mm
Outside of the "valid SAS System date window", date formats display ****
Midnight is normally displayed as 00:00:00, but when the fractions of the
second would round up to midnight, it is displayed as 24:00:00,
If you try defining this nested format on other platforms (I'm on Win95
here), you may need to replace
other = [datetime22.2]
with
other =(!datetime22.2!)
--
Peter Crawford
|