*(Q) How can I transform my variable "a" so that it only takes on values in the interval [0,1]. *(A) Following linear transformation was posted by rlevesque@videotron.ca to SPSSX-L on 2001/09/25. DATA LIST FREE /a. BEGIN DATA -5 12 85 26 -2 18 END DATA. LIST. COMPUTE dummy=1. AGGREGATE /OUTFILE='C:\\temp\\AGGR.SAV' /BREAK=dummy /minval = MIN(a) /maxval = MAX(a). MATCH FILES /FILE=* /TABLE='C:\\Temp\\AGGR.SAV' /BY dummy. COMPUTE newa=(a-minval)/(maxval - minval). ************************************. * * Extension 1. * To turn the above into a macro. Do as follows. * ************************************. SET MPRINT=no. */////////////////////. DEFINE !transf (var=!TOKENS(1) /newvar=!TOKENS(1)) COMPUTE dummy=1. AGGREGATE /OUTFILE='C:\\temp\\AGGR.SAV' /BREAK=dummy /minval = MIN(!var) /maxval = MAX(!var). MATCH FILES /FILE=* /TABLE='C:\\Temp\\AGGR.SAV' /BY dummy. COMPUTE !newvar=(!var-minval)/(maxval - minval). !ENDDEFINE. */////////////////////. * Example of use. SET MPRINT=yes. GET FILE='c:\\Program Files\\spss\\employee data.sav'. !transf var=salary newvar=nsal. EXECUTE. ************************************. * * Extension 2. * To allow transformation into any range [b,c] instead of between [0,1]. Do as follows. * ************************************. SET MPRINT=no. */////////////////////. DEFINE !transf2 (var=!TOKENS(1) /newvar=!TOKENS(1) /intbeg=!TOKENS(1) /intend=!TOKENS(1)) /* Transform var into newvar such that newvar is in interval [intbeg,intend]*/ COMPUTE dummy=1. AGGREGATE /OUTFILE='C:\\temp\\AGGR.SAV' /BREAK=dummy /minval = MIN(!var) /maxval = MAX(!var). MATCH FILES /FILE=* /TABLE='C:\\Temp\\AGGR.SAV' /BY dummy. COMPUTE !newvar=!intbeg + (!intend - !intbeg)*(!var-minval)/(maxval - minval). !ENDDEFINE. */////////////////////. * Example of use. SET MPRINT=yes. GET FILE='c:\\Program Files\\spss\\employee data.sav'. !transf2 var=salary newvar=nsal intbeg=2 intend=7. EXECUTE. * Proof. DESCRIPTIVES VARIABLES=nsal /STATISTICS=MEAN RANGE MIN MAX .