2

I have a file with more than 250 variables and more than 100 cases. Some of these variables have an error in decimal dot (20445.12 should be 2.044512).

I want to modify programatically these data, I found a possible way in a Visual Basic editor provided by SPSS (I show you a screen shot below), but I have an absolute lack of knowledge.

  • How can I select a range of cells in this language?
  • How can I store the cell once modified its data?

enter image description here

--- EDITED NEW DATA ---- Thank you for your fast reply.

The problem now its the number of digits that number has. For example, error data could have the following format:

Case A) 43998 (five digits) ---> 4.3998 as correct value. Case B) 4399 (four digits) ---> 4.3990 as correct value, but parsed as 0.4399 because 0 has been removed when file was created.

Is there any way, like:

IF (NUM < 10000) THEN NUM = NUM / 1000 ELSE NUM = NUM / 10000

Or something like IF (Number_of_digits(NUM)) THEN ...

Thank you.

Joseph
  • 149
  • 1
  • 2
  • 9

1 Answers1

2

there's no need for VB script, go this way:

open a syntax window, paste the following code:

do repeat vr=var1 var2 var3 var4.
compute vr=vr/10000.
end repeat.
save outfile="filepath\My corrected data.sav".
exe.

Replace var1 var2 var3 var4 with the names of the actual variables you need to change. For variables that are contiguous in the file you may use var1 to var4.
Replace vr=vr/10000 with whatever mathematical calculation you would like to use to correct the data.
Replace "filepath\My corrected data.sav" with your path and file name.

WARNING: this syntax will change the data in your file. You should make sure to create a backup of your original in addition to saving the corrected data to a new file.

eli-k
  • 10,898
  • 11
  • 40
  • 44
  • Thank you for your fast reply. Can you help me with the edited problem above? – Joseph Aug 22 '17 at 11:25
  • Anyway, I ve this issue now: `The only >recognized subcommands are: OUTFILE, KEEP, DROP, RENAME, MAP, COMPRESSED, >UNCOMPRESSED UNSELECTED y ENCODING.` – Joseph Aug 22 '17 at 11:32
  • 1
    Given the update, you might do something like `COMPUTE V1 = V1/(10**TRUNC(LG10(V1))).` That assumes all the values are greater than zero though (so no zeroes and no negative values). – Andy W Aug 22 '17 at 13:24
  • The issue you were having is because of a missing period at the end of my `save` command - now corrected above. – eli-k Aug 22 '17 at 14:23
  • Re your other question - I like @AndyW 's suggestion above, but if you want to use `if` conditions, your command would look like this: `if [something] [do something].` (no "then"). If you want to use "else" - here's a nice quick tutorial about using `do if` in spss: https://www.spss-tutorials.com/spss-do-if-command/ – eli-k Aug 22 '17 at 14:29