Skip to content
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

write_sav is acting inconsistently for long string variables. #752

Open
esul1121 opened this issue Apr 24, 2024 · 1 comment
Open

write_sav is acting inconsistently for long string variables. #752

esul1121 opened this issue Apr 24, 2024 · 1 comment
Labels
bug an unexpected problem or unintended behavior readstat

Comments

@esul1121
Copy link

Hello-
I don't think it's a new issue as I found multiple threads here regarding split variables from long string variables.

Here is my example and not sure how to reproduce this.

I was converting a dataframe into .sav format but when the data opened in SPSS some of the string having lengths between 500 to 8000 stayed the same while other string got split into string variables of length 255 each.

Why is it acting inconsistently? It seems like some string managed to accept the maximum original length while some strings split.

@oriloc
Copy link

oriloc commented May 27, 2024

I had the same issue recently. And I think I can narrow it down a bit.

The issue appears when exporting a data frame with multiple string variables that have similar (long) names.
For some reason, the string var gets split into multiple sub variables with 255 characters if one variable name starts with the same 8 characters like a previous one. In my example I created 4 different variables and filled them with strings of 1200 characters.
Q2_96_TEXT_text -> works fine
Q2_96_T -> works fine
Q2_96_TE -> splits the variable in multiple substrings of 255 chars
Q3_96_TE -> works fine

EXAMPLE CODE:

n <- 1200
df <- data.frame(Q2_96_TEXT_text = paste(rep("a", n), collapse = ""),
                  Q2_96_T = paste(rep("b", n), collapse = ""),
                  Q2_96_TE = paste(rep("c", n), collapse = ""),
                  Q3_96_TE = paste(rep("d", n), collapse = ""),
                 stringsAsFactors = FALSE)

   write_sav(df, path = "test.sav")

@gorcha gorcha added readstat bug an unexpected problem or unintended behavior labels Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior readstat
Projects
None yet
Development

No branches or pull requests

3 participants