Skip to content

Trailing digits (.d) in SAS DATETIMEw.d are lost upon read #327

@DanteDT

Description

@DanteDT

I believe this is related to #233.

As a result of that one, the width w of SAS date/time formats are now preserved, although the digits that SAS refers to as d "digits to the right of the decimal point" are still lost upon read.

From Doug's prior report, see examples in each of SAS's datetime formats

Further details on SAS date/time formats for numeric data:

A trivial test is attached, reading in dttm_wd.sas7bdat (zipped)

created in SAS:

data write.dttm_wd;
  attrib e8601dt length=8 format=e8601dt23.3 label='E8601DTw.d with digits to right of decimal';
  attrib datetime length=8 format=datetime22.3 label='DATETIMEw.d with digits to right of decimal';
  
  do e8601dt = '2023-10-28T01:02:33.456'dt, '2024-10-28T12:03:44.567'dt, '2025-10-28T23:04:55.678'dt;
    datetime = e8601dt;
    put e8601dt best16.3 @20 datetime best16.3;
    output;
  end;
run;

Note the numeric values of those w.d date/times:

   2014074153.456     2014074153.456
   2045736224.567     2045736224.567
   2077311895.678     2077311895.678

View original data in SAS Universal Viewer, unformatted numeric data:

Image

Image

read/write using pyreadstat 1.2.8

import pandas as pd
import pyreadstat as pyrs
dttm_wd = pyrs.read_sas7bdat('data_out/dttm_wd.sas7bdat') 
print(dttm_wd[1].readstat_variable_types)
print(dttm_wd[1].original_variable_types)

pyrs.write_xport(dttm_wd[0], 'data_out/dttm_wd.xpt')

Loss of ".d" digits in these formats.

{'e8601dt': 'double', 'datetime': 'double'}
{'e8601dt': 'E8601DT23', 'datetime': 'DATETIME22'}

View resulting XPT in SAS Univ Viewer, unformatted numeric data:

  • ISO8601 format not preserved, but numeric digits preserved
  • DATETIME format preserved, but numeric digits lost.

Image

Image

dttm_wd.zip

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