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
- 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.)
- 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 |
Note: I'm using the
havenpackage 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
Full set of formats which omit the numeric component
havenFormatDATE9DATEDDMMYY10DDMMYYDDMMYYB10DDMMYYBDDMMYYC10DDMMYYCDDMMYYD10DDMMYYDDDMMYYN6DDMMYYNDDMMYYN8DDMMYYNDDMMYYP10DDMMYYPDDMMYYS10DDMMYYSMMDDYY10MMDDYYMMDDYYB10MMDDYYBMMDDYYC10MMDDYYCMMDDYYD10MMDDYYDMMDDYYN6MMDDYYNMMDDYYN8MMDDYYNMMDDYYP10MMDDYYPMMDDYYS10MMDDYYSTIME5TIMEYYQRN7YYQRN