Can someone help me write the syntax to perform a simple operation of summing the contents of a numerical variable and then declaring for use (both in SPSS Syntax)?
For example, if I have a dataset of three cases with one variable - "score", and the three scores were 30, 40 and 25. How do I (a) return the figure of 95 (the sum of the three cases), and (b) store this variable in syntax for use in other computations?? Thanks in advance, JC ___________________________________________________________ All New Yahoo! Mail Tired of unwanted email come-ons? Let our SpamGuard protect you. http://uk.docs.yahoo.com/nowyoucan.html |
I believe you are looking for aggregate where new variables are added to
the working file. Something like this... AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK=needvarhere /totscore=sum(score). You will need a BREAK variable, so if you want an overall total, your BREAK variable should be a constant. Melissa The bubbling brook would lose its song if you removed the rocks. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Cardiff Tyke Sent: Tuesday, February 20, 2007 8:50 AM To: [hidden email] Subject: [SPSSX-L] Declaring and Summing a Variable Can someone help me write the syntax to perform a simple operation of summing the contents of a numerical variable and then declaring for use (both in SPSS Syntax)? For example, if I have a dataset of three cases with one variable - "score", and the three scores were 30, 40 and 25. How do I (a) return the figure of 95 (the sum of the three cases), and (b) store this variable in syntax for use in other computations?? Thanks in advance, JC ___________________________________________________________ All New Yahoo! Mail - Tired of unwanted email come-ons? Let our SpamGuard protect you. http://uk.docs.yahoo.com/nowyoucan.html PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
In reply to this post by Cardiff Tyke
Does this do what you want?
** sample data DATA LIST FREE /id. BEGI DATA 30 40 25 END DATA. COMPUTE nobreak EQ 1. AGGREGATE OUTFILE = * MODE = ADDVARIABLES /BREAK = nobreak /totscore = SUM(score). This will put the total score on every case in the file. --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Cardiff Tyke Sent: Tuesday, February 20, 2007 8:50 AM To: [hidden email] Subject: Declaring and Summing a Variable Can someone help me write the syntax to perform a simple operation of summing the contents of a numerical variable and then declaring for use (both in SPSS Syntax)? For example, if I have a dataset of three cases with one variable - "score", and the three scores were 30, 40 and 25. How do I (a) return the figure of 95 (the sum of the three cases), and (b) store this variable in syntax for use in other computations?? Thanks in advance, JC ___________________________________________________________ All New Yahoo! Mail - Tired of unwanted email come-ons? Let our SpamGuard protect you. http://uk.docs.yahoo.com/nowyoucan.html |
Free forum by Nabble | Edit this page |