Skip to content

SAS DATEAMPM format incorrectly converted to date instead of datetime #789

@gowerc

Description

@gowerc

It looks like DATEAMPMw.d variables are being incorrectly auto mapped to being date instead of datetime via haven::read_sas().

At least from the docs:

DATEAMPMw.d - Writes datetime values in the form ddmmmyy:hh:mm:ss.ss with AM or PM.

link

Repex:

sas

libname here "./";
data here.dat;
    format us_dt_ampm_short DATEAMPM19.5 ;
    input  reference :datetime20. ;
    us_dt_ampm_short = reference;
    datalines;
01JAN2024:12:34:56.8765
30JUL1756:00:45:00.1234
03MAR2092:01:55:10.0987
25DEC2024:23:05:20.6789
;
run;

R

x <- haven::read_sas("dat.sas7bdat")
class(x$us_dt_ampm_short)  # "Date"
attributes(x$us_dt_ampm_short)$format.sas  #  "DATEAMPM19.5"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions