Read SAS dataset variable names and lables

Hi

Is there a function in the haven package that would allow to directly extract the names of a SAS dataset? Is there one to read the labels?

I could not find any hints from the read_sas function documentation. Right now, the best (but a bit inefficient) I can do is to read the file with read_sas and get the variables names with the names function and the labels with some mix of sapply and attr...

Any suggestion will be welcome.

1 Like

I expect you are asking for a direct approach because for your use case it might be considered wasteful to read entire dataset, thereby make a dataframe, and from that get column names .
The good news is that read_sas has an n_max Param to limit number of records. You could test if it works for n_max 0 as well as for n_max 1

2 Likes

@pomchip: I'm not sure your issue is similar, but a recent encounter with labeled data led me to use haven's as_factor() command, which lets you explicitly get your hands on the labels.

Thanks

n_max does the trick! I had to update to a newer version of haven, as the version I had installed did not provide this argument.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.