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
SPSS AnswerNet: Result 

Solution ID:	 	100008355	
Product:	 	SPSS Base 	
Version:	 		
O/S:	 		
Question Type:	 	Syntax/Batch/Scripting	
Question Subtype:	 	Data Transformations	
Title:
Computing percentages based on the value of the first case 
Description:
Q. 
I have a data set that has, for example, 26 cases and 10 variables. 
For each case I want to divide the value for a given variable by 
the value of the same variable for the first case. I also want to 
do this for each of the ten variables. All I can think of to do 
is some sort of COMPUTE statements using lags, but this would be 
awfully cumbersome. Is there an easy way to do this sort of thing? 
A. 
There is a way to do this that would involve only one COMPUTE command. 
Here is the syntax that we can use (this syntax assumes that we have 
26 cases and the first case is the case we want to use as the percentage 
base for each of the ten variables. We also assume that the first case 
has valid values for all the pertinent variables): 
** First we transpose the entire data set. 
FLIP. 
** Here we create a series of variables that is a percentage 
** of the VAR001 variable (which consists of the values of 
** the first case in the file). 
DO REPEAT a=var002 to var025 / b=newv002 to newv025. 
COMPUTE b=a/var001. 
END REPEAT. 
EXECUTE. 
** Now we re-transpose the data file. 
FLIP. 
** Here we create a new case counter and select the cases 
** based on that counter. Since we had 26 cases in our 
** original data set, we now have 51 cases in our data file. 
** We want to select case no. 1 (the "standard" case) and 
** cases 27 through 51 since those cases have the percentages. 
COMPUTE counter=$casenum. 
EXECUTE. 
SELECT IF (counter=1 or counter ge 27). 
EXECUTE. 
The result is that we have converted the values of cases 2 
through 26 from a raw score to a percentage using case 1 as 
the denominator.