Skip to content

Add support for e8601dn and b8601dn SAS formats #780

@gowerc

Description

@gowerc

SAS has the formats b8601dn & e8601dn which are used to display just the date component of a datetime variable. Currently haven appears to just read these in as numeric rather than casting to POSIXct/POSIXt. Interestingly similar formats such as b8601dt & e8601dt already appear to be supported.

libname outlib "./data";
data outlib.test_datetimes;
    format 
        my_dt datetime23.4
        dt_8601n b8601dn.
        dt_8601t b8601dt.
        dt_8601en e8601dn.
        dt_8601et e8601dt.
    ;
    input
        my_dt :datetime20. 
    ;
    array dts{*} dt_8601n dt_8601t dt_8601en dt_8601et;
    do i = 1 to dim(dts);
        dts{i} = my_dt;
    end;
    drop i;
    datalines;
01JAN2024:12:34:56.8765
30JUL1756:00:45:00.1234
03MAR2092:01:55:10.0987
25DEC2024:23:05:20.6789
.
;
run;
dat <- haven::read_sas("./data/test_datetimes.sas7bdat")
dat[, c("dt_8601n", "dt_8601t", "dt_8601en", "dt_8601et")]
# A tibble: 5 × 4
      dt_8601n dt_8601t               dt_8601en dt_8601et          
         <dbl> <dttm>                     <dbl> <dttm>             
1  2019731697. 2024-01-01 12:34:56  2019731697. 2024-01-01 12:34:56
2 -6419344500. 1756-07-30 00:45:00 -6419344500. 1756-07-30 00:45:00
3  4170966910. 2092-03-03 01:55:10  4170966910. 2092-03-03 01:55:10
4  2050787121. 2024-12-25 23:05:20  2050787121. 2024-12-25 23:05:20
5          NA  NA                           NA  NA  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions