Help with simple syntax

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with simple syntax

Cardiff Tyke
All,

Apologies for the simple nature of this question - I've been wowed by some of the submissions to the list in the archive and I wish I could understand just 1% of them.  Anyway, as part of my job I currently manipulate datasets with SPSS, mostly with simple syntax I have gleaned from the Paste buttons within dialog boxes.  However, one thing I cannot do is sum the total values within a variable for use within a compute command.

As an example, I am looking at the balance of a single customers account within a dataset and I wish to know the percentage that the account constitutes of the overall balance.  Currently I am running Compare Means->Sum for the total of the variable "balance" and then I am using the Compute command to create a variable called BalPerc which is simply (Balance/Sum of Balance)*100.  I wish to know how to automate this process so I do not have to repeat this sequence over and over again.

Any help would be greatly appreciated,
John
Reply | Threaded
Open this post in threaded view
|

Re: Help with simple syntax

Ken Chui
Please try this:

The

*///// First open your dataset .

*///// Compute a constant for merging file later .
COMPUTE MERGE_CONSTANT = 1 .
EXECUTE .

*///// Use aggregate to create a file "total.sav" in temp folder; with
variable "C1" summed up .
AGGREGATE
  /OUTFILE='C:\temp\total.sav'
  /BREAK=MERGE_CONSTANT
  /C1_sum = SUM(C1).

*///// The aggregate should only contain two variables and one case, namely
1 for Merge_constant and the sum of C1 as C1_sum.  Now we are ready for
multiple merging.
MATCH FILES /FILE=*
 /TABLE='C:\temp\total.sav'
 /BY MERGE_CONSTANT.
EXECUTE.

*///// Finally get rid of the merge_constant
DELETE VARIABLE MERGE_CONSTANT .
EXECUTE .

Hope this helps.

-Ken
Reply | Threaded
Open this post in threaded view
|

Re: Help with simple syntax

Ken Chui
In reply to this post by Cardiff Tyke
Oh... if you would like to run that as a whole single step, we have to add
an extra "Execute"... revised version below:

COMPUTE MERGE_CONSTANT = 1 .
EXECUTE .
AGGREGATE
  /OUTFILE='C:\temp\total.sav'
  /BREAK=MERGE_CONSTANT
  /C1_sum = SUM(C1).
EXECUTE .

MATCH FILES /FILE=*
 /TABLE='C:\temp\total.sav'
 /BY MERGE_CONSTANT.
EXECUTE.
DELETE VARIABLE MERGE_CONSTANT .
EXECUTE .

This whole chunk should work smoothly.