Search code examples
transformspssdata-transform

Dividing the values by their mean for many variables


I wish to conduct a data Transformation by dividing each case in a variable by that variable's mean. I have 91 variables in my dataset. I create the means using the AGGREGATE function:

  AGGREGATE
  /OUTFILE=* MODE = ADDVARIABLES
  /BREAK=
  /mean_1 to mean_91= MEAN(Var1 TO Var91).

This code is giving me each variable's mean in the same dataset, but in order to divide each case by its mean, I have created a new dataset with a command that can repeat itself. The Problem is to Change from mean_1 to mean_2 ...... mean_91.

COMPUTE CMD = CONCAT("COMPUTE",RTRIM(Name),".Norm =",RTRIM(Name),"/mean",1,".").

How can i make sure that in the next line, the number 1 will become 2, then 3 and so on?


Solution

  • There is a much simpler way to accomplish your task. After calculating the means like you did, you can loop through all the variables like this:

    do repeat vr=var1 to var91 /mn=mean_1 to mean_91 /nrm=norm1 to norm91.
       compute nrm=vr/mn.
    end repeat.