Hi everyone,
I have a python script that needs to read data, and, for some reason (related to our python pipeline) we have to read a single file.
When exporting SAS data containing formats with labels, two files are exported (sas7bdat for the data without applying the labels, sas7bcat for the catalog containing the labels).
I would like to export the sas7bdat file with the data containing the labels applied ; could you please help me with the correct approach for this ?
(I really couldn't find a clear answer ; seems that put(data_column, $format_name) does it for one column but I would like a synthetic way to get this done in one shot on all columns at the export).
Many thanks !!
If the dataset has formats applied to columns, and the formats are not available, then you are stuck with the raw (unformatted) values.
If the Python module cannot deal with such an event, you need to ask the source for the dataset to remove the formats before sending you the dataset.
If this is for non-commercial purposes, you could do that yourself with SAS On Demand.
Run a PROC CONTENTS to determine where custom formats are used.
Then run a DATA step where you use PUT or VVALUE functions to convert raw values to formatted values, or where you simply remove formats that don't do anything special (e.g. currency formats). Take care to create new variables with sufficient length.
Why not just dump the data to a text file. That will preserve the formatting since everything will be text. Then send the text file to your Python code instead of the SAS dataset.
But why does it matter? What is the format doing?
If the format is just doing a one to one replacement of the raw value with some decoded text why not just use the raw (coded) values in your Python code?
Or are you somehow using the format to collapse the raw data so that multiple distinct raw values are mapped into a single formatted value?
You could use PROC PRINT and ODS OUTPUT to redirect the formatted values to a new dataset.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.