Skip to content

Trailing numerals in SAS Date/Time/DateTime formats are lost upon read #233

@dgkf

Description

@dgkf

Note: I'm using the haven package in R to read in the data. I tried to trace the formatting as far down into C as my limited C knowledge allows, but it's very possible the information loss is happening on the R side.

SAS datetimes with a numeric qualifier (eg TIME5.) are read in without the trailing numeral (TIME). Would it be possible to include the numeric part of the format string?

Steps to Reproduce

  1. Create a SAS dataset with date, time or datetime variables with a specified format length. (SAS script and resulting dataset attached (sas_datetime_example_and_data.zip) with columns for each of SAS's datetime formats using both character and numeric internal representations.)
  2. Read in data in R
    df <- haven::read_sas("datetimes.sas")
    
    # extract readstat format from SAS column created using
    # FMT_TIME5=input(20999, TIME5.); format FMT_TIME5: TIME5.;
    attr(df[["FMT_TIME5"]], "format")  
    # TIME   # expected "TIME5"

Full set of formats which omit the numeric component

SAS Format (9.04) R haven Format
DATE9 DATE
DDMMYY10 DDMMYY
DDMMYYB10 DDMMYYB
DDMMYYC10 DDMMYYC
DDMMYYD10 DDMMYYD
DDMMYYN6 DDMMYYN
DDMMYYN8 DDMMYYN
DDMMYYP10 DDMMYYP
DDMMYYS10 DDMMYYS
MMDDYY10 MMDDYY
MMDDYYB10 MMDDYYB
MMDDYYC10 MMDDYYC
MMDDYYD10 MMDDYYD
MMDDYYN6 MMDDYYN
MMDDYYN8 MMDDYYN
MMDDYYP10 MMDDYYP
MMDDYYS10 MMDDYYS
TIME5 TIME
YYQRN7 YYQRN

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions