Skip to content

Xport files NULL original variable type and Informats #287

@DanteDT

Description

@DanteDT

UPDATED based on follow-ups:
The README statement should state:

  • "Probably you want to read a file produced in the original application and use meta.original_variable_types to get the formats."
  • There is one issue with handling of NULL formats, noted in discussion below

To Reproduce

Create XPT files from SAS 9.4

/*** Create V5 XPT ***/
%LOC2XPT(FILESPEC='../output/stks_v5.xpt' , LIBREF=SASHELP, MEMLIST=STOCKS, FORMAT=V5)

/*** Create V8 XPT ***/
%LOC2XPT(FILESPEC='../output/stocks_v8.xpt' , LIBREF=SASHELP, MEMLIST=STOCKS, FORMAT=V8)

Check meta read in by read_xport()

import pyreadstat as prs
import sys

print(f"Python version: {sys.version}")
print(f"pyreadstat version: {prs.__version__}")

df_v5, meta_v5 = prs.read_xport("stks_v5.xpt")
df_v8, meta_v8 = prs.read_xport("stocks_v8.xpt")

try:
    meta_v5.original_variable_types
    meta_v8.original_variable_types
except AttributeError as err:
    print(f"failure message: {err}")

prs.write_xport(df_v5,
                "prs_v5.xpt",
                table_name='PRS_STK5',
                variable_format=meta_v5.original_variable_types,
                column_labels=meta_v5.column_labels)
prs.write_xport(df_v8,
                "prs_v8.xpt",
                table_name='PRS_STK8',
                variable_format=meta_v8.original_variable_types,
                column_labels=meta_v8.column_labels)

Code works fine. One note about implicit formats in discussion, below

Python version: 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)]
pyreadstat version: 1.2.8

File example
Above should suffice to reproduce?

Expected behavior
README is up to date, and approach works.

Setup Information:
See code output above

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions