New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Member name in SAS xport file generated by write_xpt is hard coded to "DATASET" #328

Closed
sasutils opened this Issue Dec 21, 2017 · 12 comments

Comments

Projects
None yet
3 participants
@sasutils
Copy link

sasutils commented Dec 21, 2017

There is no way to tell the write_xpt function what member name to use for the SAS transport file that it generates. Instead is it generating a header record that has the member name hard coded as "DATASET ".

So if I use this line to write the data frame named ABC to a file named 'abc.xpt'
write_xpt(ABC,"abc.xpt")
and then try to read it into SAS I will end up with a dataset named DATASET instead of one named ABC.

The user should be able to specify the member name that they want their SAS dataset to have. It would be easier to use if the default member name used was based on the input object's name, or perhaps the name of the target file.

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jan 7, 2018

@evanmiller looks like this is currently hardcoded into sas7bdat_emit_header. Any chance we could have it as a setting?

@sasutils

This comment has been minimized.

Copy link

sasutils commented Jan 7, 2018

@evanmiller

This comment has been minimized.

Copy link
Contributor

evanmiller commented Jan 7, 2018

This could be added as a setting in ReadStat.

XPORT file can include both the (symbolic) member name and the (plain language) file label. It's not clear to me if SAS7BDAT files also have both fields.

@sasutils

This comment has been minimized.

Copy link

sasutils commented Jan 8, 2018

Functionality should be added to ReadStat and then just surfaced in haven.

Both Xport files and SAS datasets can store member names and member labels. The V5 transport files the member names are limited to 8 bytes and member label is limited to 40 bytes. For V8 transport files and SAS datasets (sas7bdat format) can use 32 byte member names and 256 byte member labels.

@evanmiller

This comment has been minimized.

Copy link
Contributor

evanmiller commented Jan 22, 2018

On the ReadStat side this is available now through readstat_writer_set_table_name:

readstat_error_t readstat_writer_set_table_name(readstat_writer_t *writer, const char *table_name)

I'm open to another name for the function. SAS variously refers to this string as the member name, table name, and data set name. (set_data_set_name seemed liable to cause confusion.)

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jan 22, 2018

set_dataset_name() could be a possible option, but I think table_name is fine

@evanmiller

This comment has been minimized.

Copy link
Contributor

evanmiller commented Jan 22, 2018

Might change the new metadata type to dataset and then do something like

readstat_dataset_get_name()
readstat_dataset_get_label()
readstat_dataset_get_var_count()
readstat_dataset_get_row_count()

Then on the write side

readstat_writer_set_dataset_name() // formerly table_name
readstat_writer_set_dataset_label() // formerly file_label

@hadley hadley closed this in cef5421 Feb 15, 2018

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Feb 15, 2018

@sasutils I think this should now work, but I have no easy way to check. Can you please try it out?

@sasutils

This comment has been minimized.

Copy link

sasutils commented Feb 15, 2018

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Feb 15, 2018

See the docs for the name argument, and let me know if they're not clear.

@sasutils

This comment has been minimized.

Copy link

sasutils commented Feb 18, 2018

Looks good. I was able to create XPORT from R and read with SAS 9.4 on Windows.

When NAME= not used then it used the base name of the output file.
Or I could use the NAME= and set a different name.

@lock

This comment has been minimized.

Copy link

lock bot commented Aug 17, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Aug 17, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.