LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2003)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sat, 13 Sep 2003 18:40:22 -0400
Reply-To:   Raynald Levesque <rlevesque@videotron.ca>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   Raynald Levesque <rlevesque@videotron.ca>
Subject:   Re: It's simple but takes time
In-Reply-To:   <50706202F3005D4DB51EABCCF73728104C04C5@mail-kk.bognet.gr>
Content-type:   text/plain; charset=windows-1253

Hi

The best way to automate this is to use a macro.

*////////////////. DEFINE !addvar ( func = !CHAREND('/') /var = !CHAREND('/') /breakvr = !DEFAULT(nobreak) !CHAREND('/') /newvar= !CHAREND('/') /file = !TOKENS(1))

GET FILE = !file. !IF (!UPCASE(!breakvr)='NOBREAK') !THEN COMPUTE nobreak=1. !IFEND SORT CASES BY !breakvr. !LET !f=!func AGGREGATE OUTFILE = "c:\temp\aggr.sav" /PRESORTED /BREAK = !breakvr !DO !new !IN (!newvar) /!new = !HEAD(!f)(!var) !LET !f=!TAIL(!f)!DOEND. MATCH FILES FILE = * /TABLE = "c:\temp\aggr.sav" /BY=!breakvr. EXECUTE. !ENDDEFINE. *////////////////.

SET MPRINT=yes. * Example 1: Add variable meansal to the Employee data.sav file; where meansal contains mean salary of that jobcat. !addvar func=mean /var=salary /breakvr=jobcat /newvar=meansal /file='c:\program files\spss\employee data.sav'.

* Example 2: Add variable sdsal to the Employee data.sav file; where sdsal contains the sd of salary. !addvar func=sd /var=salary /newvar=sdsal /file='c:\program files\spss\employee data.sav'.

* Example 3: Add mean, sd and max of salary to Employee data.sav. !addvar func=mean sd max /var=salary /newvar=meansal sdsal maxsal /file='c:\program files\spss\employee data.sav'.

Note that for convenience, the macro could be saved in a file called "utils.sps" then only two commands would be reequired to add variables:

INCLUDE "path\utils.sps" !addvar func=mean sd max /var=salary /newvar=meansal sdsal maxsal /file='c:\program files\spss\employee data.sav'.

Regards

Raynald Levesque rlevesque@videotron.ca Visit my SPSS site: http://pages.infinit.net/rlevesqu/

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Mitrakos Theodoros Sent: September 12, 2003 3:07 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: It's simple but takes time

Dear all

When working in SPSS sometimes I want to create a new variable (or better a memory variable or a constant) with the sum (or the variance or the maximum value) of an existing in my data file variable. The only solution that I have found for the time being is that: the use of aggregate command in order to save in another file the sum (or the variance or the maximum value) of the existing variable and then I merge this file with the original one .... This procedure takes time and risk for error. I am looking for somthing easier. Could I create a memory variable or a constant containing the sum of an existing variable?

Thanks in advance for any suggestions.

M. Theo.


Back to: Top of message | Previous page | Main SPSSX-L page