selik / xport

Python reader and writer for SAS XPORT data transport files.
MIT License
49 stars 24 forks source link

extract metadata #56

Closed rashed120 closed 2 years ago

rashed120 commented 3 years ago

Hi,

If i open xpt file in notepad, i can see column name there. Could you please guide me how can i extract column name form xpt file using xport?

selik commented 3 years ago

If you do this:

import xport.v56

with open('example.xpt', 'rb') as f:
    library = xport.v56.load(f)
help(library)

Do you get something that explains it?

selik commented 3 years ago

Sorry, I should have waited until I had a chance to write more. So, the load function parses a SAS dataset library, which can have many members. Each has a name, so the library is kind-of a dictionary of members. If you look at the library's keys, you'll see the member names. Pick out a member and it's a subclass of a Pandas DataFrame, the column names matching the SAS names.