Lỗi variable name contains an illegal character spss

Following on this issue, I also got an error while trying to save the data as .sav. It turns out that illegal characters are more than just a "." . Illegal characters include spaces, hyphens, apostrophes, and square brackets. This line worked for me, after spending three hours debugging the code. Maybe a better error message would have helped, something like "check if your variable names include a white space, hyphen, apostrophe, square bracket, etc"

Lỗi variable name contains an illegal character spss

Hiện tại, Super Render VN hỗ trợ hầu hết các software, renderers và plugin 3D phổ biến như 3D Max, Blender, C4D, Maya, Arnold, V-Ray, Corona, Redshift, Houdini, After Effect, v.v … Hãy thử trải nghiệm dịch vụ cloud render farm tại đây

HTML

style="bottom: 0; left: 0; position: absolute; right: 0; top: 0; border: 0; height: 100%; width: 100%;" src="https://mediahub.unl.edu/media/5715?format=iframe&autoplay=0" title="Video Player: SPSS for Beginners Part 1" allowfullscreen

SPSS allows you to rename variables either via its Variable View or by using syntax. There are a number of rules governing the naming of variables.

Rules & Best Practices for Naming Variables

  1. Names can be safely up to 32 characters long. Names may include alphanumeric characters, non-punctuation characters, and a period (.).
  2. You can’t have a space in a variable name.
  3. Don’t end a variable name with a period.
  4. Don’t end a variable name with an underscore.
  5. You can use periods and underscores within a variable name.
  6. You can use upper and lower case, and a mixture thereof, within a variable name.
  7. You can’t use SPSS reserved keywords as a variable name (i.e., you can’t use ALL, AND, BY, EQ, GE, GT, LE, LT, NE, NOT, OR, TO or WITH).
  8. Each variable must be unique.

***************

That’s it, short and sweet. If you follow those rules when naming variables, you’re not going to go wrong.

I wanted to export a Jamovi database to SPSS (.sav file). However, when I tried to do so, I got a quickly disappearing message saying "save failed a provided name contains an illegal character" (this also occurred to .sas7bdat, .xpt, and .dta files).

Changing the filename did not solve the issue. Exporting as .RData worked, however.

Thanks to a stackoverflow post (1) I then proceeded to export the data from R/RStudio which basically gave me the same answer, namely: "Error in write_sav_(data, normalizePath(path, mustWork = FALSE), compress = compress) : Writing failure: A provided name contains an illegal character."

Further research led me to yet another stackoverflow post (2) that made me realise that by "name", the error message meant "variable name". I noticed that one variable name had a * (star) character which I changed for an X and 3 other variable names that had a - (minus) character that I promptly removed.

After that export went as a breeze (but only for .sav / SPSS files, it did not work for .sas7bdat, .xpt, and .dta files; that is why I did not dare answer to the "Error exporting the data as SPSS or dta" post (3)).

I wonder if pasting as plain text into word first and then to paste into SPSS would work? Possibly some formatting is being inserted by excel that SPSS doesn't like? Worth a shot if not tried already