1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
*(Q) I have four scales whose minimum and maximum values are different. I would
like to change them so they all range from 0 to 1. What I have been doing is
writing a syntax code for each of the scales with their minimum values in
the expression and then dividing everything by their range (e.g. COMPUTE
scale2 = (scale1-0.13)/0.6).
Is there a way to do this so I don't have to manually enter the values for
each scale?

* (A) Posted to SPSSX-L by Raynald Levesque.

GET FILE='c:\\program files\\spss\\employee data.sav'.

*/////////////.
DEFINE !rescale (var=!TOKENS(1) /newvar=!TOKENS(1))
SAVE OUTFILE='c:\\temp\\data file.sav'.
COMPUTE nobreak=1.
AGGREGATE OUTFILE=*
  /PRESORTED
  /BREAK=nobreak
  /min=MIN(!var) /max=MAX(!var).
COMPUTE range=max-min.
* This will work if decimal separator in your system is set to dot (.). Otherwise you'll likely to get 
  error in executing syntax with INCLUDE command below.
WRITE OUTFILE="C:\\temp\\rescale.sps"
  /"COMPUTE " !QUOTE(!newvar) "=(" !QUOTE(!var) "-" min(F12.11) ")/" range(F12.11) ".".
EXECUTE.
GET FILE='c:\\temp\\data file.sav'.
INCLUDE "C:\\temp\\rescale.sps".
!ENDDEFINE.
*/////////////.

* example rescale salary to be between 0 and 1.
SET MPRINT=yes.
!rescale var=salary newvar=salary2.
SET MPRINT=no.
* show that it works.
GRAPH
  /SCATTERPLOT(BIVAR)=salary WITH salary2
  /MISSING=LISTWISE .

* example rescale salbegin to be between 0 and 1.
SET MPRINT=yes.
!rescale var=salbegin newvar=salbegin2.
SET MPRINT=no.
* show that it works.
GRAPH
  /SCATTERPLOT(BIVAR)=salbegin WITH salbegin2
  /MISSING=LISTWISE .