Question

In my SPSS Syntax Script I compute a bunch of formulas for each cases.

Let' say this is my data:

id    value
 1      34
 2      12
 3      94

I now compute a new variable where I need the number of cases in the file (number of ids) So

COMPUTE newvar = value/ NUMBER OF CASES

in this example NUMBER OF CASES would be 3.

Is there a command for this? thx

Was it helpful?

Solution

You can use the AGGREGATE command without a break variable to return the number of cases in the dataset. Example below:

DATA LIST FREE / ID Value.
BEGIN DATA
1 34
2 12
3 94
END DATA.

AGGREGATE OUTFILE=* MODE=ADDVARIABLES
  /BREAK
  /NumberOfCases=N.

COMPUTE NewVar = Value/NumberOfCases.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top