1
votes

I have a dataset with columns parcomm, subcomm, ccs, prov, data. I'd like to have aggregate result of data for the first four columns. I used spss code as stated below

DEFINE myvars (arg=TOKENS(4)).
aggregate 
/OUTFILE=* MODE=ADDVARIABLES 
/BREAK=!arg
/sum_!arg=sum(data).
!ENDDEFINE.

myvars parcomm subcomm ccs prov.  

The error shows

Error # 10933 in column 2. Text: parcomm The definition of a new variable on the AGGREGATE command must be terminated by a slash. Execution of this command stops.

When I tried just one token, I have the following error:

 DEFINE myvars (arg=!TOKENS(1)). 
 aggregate  /OUTFILE=* MODE=ADDVARIABLES  
 /BREAK=!arg   
 /sum_sum=sum(data). 
 !ENDDEFINE. 
 myvars arg=prov.  

Error # 10934 in column 48.  Text: prov.   The AGGREGATE command specifies an unknown existing variable name. Execution of this command stops.

How should I fix the problem?

1
you cannot use !arg like this: ` /sum_!arg=sum(data).` what are you trying to achieve here ? what is the non-macro syntax you would like to run ? In your second piece of code, you are probably using a non-existent variable - either data or prov do not exist in your dataset - horace_vr

1 Answers

0
votes

If I understand right, what you are trying to do is to run aggregate with a different break variable each time, adding a sum aggregation to the dataset. A macro can help to loop through the variables, but what your macro is missing is the actual loop. Try this:

First just creating a little dataset to demonstrate on:

data list list/parcomm subcomm ccs prov data (5f2).
begin data
1 2 3 4 25
3 2 3 2 33
1 2 3 2 42
4 1 4 1 66
end data.

Now the following macro will loop through the variable list in the macro call and run aggregate on each of them:

DEFINE myvars (arg=!cmdend).
!do !vr !in(!arg)
aggregate 
/OUTFILE=* MODE=ADDVARIABLES 
/BREAK=!vr
/!concat("sum_",!vr) = sum(data).
!doend
!ENDDEFINE.

myvars arg=parcomm subcomm ccs prov.