probably a simple question, but I could not find an answer
for the sum of variables SPSS provides SUM(v1 to vN). What about the multiplication? v1 * v2 * ... v(n-1) * v(n).
Dr. Frank Gaeth
|
No function, not that I recall seeing.
But: Compute product=1. Do repeat x=v1 to v(n). Compute product=product*x. End repeat. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of drfg2008 Sent: Friday, October 04, 2013 6:13 AM To: [hidden email] Subject: Function probably a simple question, but I could not find an answer for the sum of variables SPSS provides SUM(v1 to vN). What about the multiplication? v1 * v2 * ... v(n-1) * v(n). ----- Dr. Frank Gaeth FU-Berlin -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
D'oh! Yes...that is far more direct that the "Rubish" method I posted (using sums of logs etc) and then promptly deleted from the Nabble archive...but not before it reached the archives at UGA, unfortunately.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
This post was updated on .
In reply to this post by Maguin, Eugene
And to mimic the treatment of missing values:
replace: Compute product ... with IF NOT MISSING(x) Product=Pruduct * x. ---
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Bruce Weaver
That was a good Rubish method! It illustrates several elements.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver Sent: Friday, October 04, 2013 9:11 AM To: [hidden email] Subject: Re: Function D'oh! Yes...that is far more direct that the "Rubish" method I posted (using sums of logs etc) and then promptly deleted from the Nabble archive...but not before it reached the archives at UGA, unfortunately. Maguin, Eugene wrote > No function, not that I recall seeing. > But: > > Compute product=1. > Do repeat x=v1 to v(n). > Compute product=product*x. > End repeat. > > Gene Maguin > > -----Original Message----- > From: SPSSX(r) Discussion [mailto: > SPSSX-L@.UGA > ] On Behalf Of drfg2008 > Sent: Friday, October 04, 2013 6:13 AM > To: > SPSSX-L@.UGA > Subject: Function > > probably a simple question, but I could not find an answer > > for the sum of variables SPSS provides SUM(v1 to vN). > > What about the multiplication? v1 * v2 * ... v(n-1) * v(n). > > > > > > ----- > Dr. Frank Gaeth > FU-Berlin > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the command. To leave the > list, send the command SIGNOFF SPSSX-L For a list of commands to > manage subscriptions, send the command INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the command. To leave the > list, send the command SIGNOFF SPSSX-L For a list of commands to > manage subscriptions, send the command INFO REFCARD ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722374.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
I've used Bruce's method in matrix mode. I'll have to go back to see if Gene's works there as well. Anyway, I guess Bruce and I just like dumpster diving.
Brian -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Maguin, Eugene Sent: Friday, October 04, 2013 10:03 AM To: [hidden email] Subject: Re: Function That was a good Rubish method! It illustrates several elements. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver Sent: Friday, October 04, 2013 9:11 AM To: [hidden email] Subject: Re: Function D'oh! Yes...that is far more direct that the "Rubish" method I posted (using sums of logs etc) and then promptly deleted from the Nabble archive...but not before it reached the archives at UGA, unfortunately. Maguin, Eugene wrote > No function, not that I recall seeing. > But: > > Compute product=1. > Do repeat x=v1 to v(n). > Compute product=product*x. > End repeat. > > Gene Maguin > > -----Original Message----- > From: SPSSX(r) Discussion [mailto: > SPSSX-L@.UGA > ] On Behalf Of drfg2008 > Sent: Friday, October 04, 2013 6:13 AM > To: > SPSSX-L@.UGA > Subject: Function > > probably a simple question, but I could not find an answer > > for the sum of variables SPSS provides SUM(v1 to vN). > > What about the multiplication? v1 * v2 * ... v(n-1) * v(n). > > > > > > ----- > Dr. Frank Gaeth > FU-Berlin > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the command. To leave the > list, send the command SIGNOFF SPSSX-L For a list of commands to > manage subscriptions, send the command INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the command. To leave the > list, send the command SIGNOFF SPSSX-L For a list of commands to > manage subscriptions, send the command INFO REFCARD ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722374.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
In reply to this post by Maguin, Eugene
You're very kind, Gene. ;-) I think it would only be "good" if you already had a set of log-transformed variables in the data file (i.e., Log1 to LogN = the natural logs of Var1 to VarN), in which case...
COMPUTE Product = Exp(SUM(Log1 to LogN)). Otherwise, it's just adding unnecessary steps in comparison to your method (with David's modification to deal with missing data).
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by Bruce Weaver
There is an edge case with David's solution:
And to mimic the treatment of missing values: replace: Compute product ... with IF NOT MISSING(x) Product=Product * x. If all the x's are missing, the result is 1, the initial value, instead of missing so the all missing case should be checked. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Bruce Weaver <[hidden email]> To: [hidden email], Date: 10/04/2013 07:11 AM Subject: Re: [SPSSX-L] Function Sent by: "SPSSX(r) Discussion" <[hidden email]> D'oh! Yes...that is far more direct that the "Rubish" method I posted (using sums of logs etc) and then promptly deleted from the Nabble archive...but not before it reached the archives at UGA, unfortunately. Maguin, Eugene wrote > No function, not that I recall seeing. > But: > > Compute product=1. > Do repeat x=v1 to v(n). > Compute product=product*x. > End repeat. > > Gene Maguin > > -----Original Message----- > From: SPSSX(r) Discussion [mailto: > SPSSX-L@.UGA > ] On Behalf Of drfg2008 > Sent: Friday, October 04, 2013 6:13 AM > To: > SPSSX-L@.UGA > Subject: Function > > probably a simple question, but I could not find an answer > > for the sum of variables SPSS provides SUM(v1 to vN). > > What about the multiplication? v1 * v2 * ... v(n-1) * v(n). > > > > > > ----- > Dr. Frank Gaeth > FU-Berlin > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the command. To leave the > list, send the command SIGNOFF SPSSX-L For a list of commands to manage > subscriptions, send the command INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722374.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
Yes, that "edge case" occurred to me too. So something like this, maybe:
new file. dataset close all. DATA LIST list /v1 to v3 (3f5.0). BEGIN DATA 1 2 3 3 4 5 7 8 9 1 3 5 2 4 6 3 5 7 4 6 8 5 7 9 5 3 999 5 999 999 999 999 999 END DATA. MISSING VALUES all(999). COMPUTE SumVars = SUM(v1 to v3). NUMERIC Product(f8.0). DO IF nvalid(v1 to v3) GT 0. /* There is at least one valid value. - COMPUTE Product=1. - DO REPEAT v = v1 to v3. - IF NOT MISSING(v) Product = Product*v. - END REPEAT. END IF. FORMATS SumVars(f8.0). LIST. OUTPUT: v1 v2 v3 SumVars Product 1 2 3 6 6 3 4 5 12 60 7 8 9 24 504 1 3 5 9 15 2 4 6 12 48 3 5 7 15 105 4 6 8 18 192 5 7 9 21 315 5 3 999 8 15 5 999 999 5 5 999 999 999 . .
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Bruce, I took the liberty of including your syntax in a macro so multiple replacements wouldn't be necessary. I also added a replacement of missing data with 999. I know it's a no-no to leave cells empty, but in our experience, groups whose data we analyze don't always use a code for missing. The macro presumes your data.
preserve. set printback=off mprint=off. define smvars (var1=!charend('/')/varn=!charend('/')). do repeat v=!var1 to !varn . if missing(v) v=999 . end repeat . execute . missing values all(999) . COMPUTE SumVars = SUM(!var1 to !varn). NUMERIC Product(f8.0). DO IF nvalid(!var1 to !varn) GT 0 . /* There is at least one valid value. - COMPUTE Product=1. - DO REPEAT v = !var1 to !varn . - IF NOT MISSING(v) Product = Product*v . - END REPEAT. END IF . FORMATS SumVars(f8.0). LIST. !enddefine. restore. /* Macro Call Line . */ smvars var1=v1/varn=v3 . -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver Sent: Friday, October 04, 2013 11:56 AM To: [hidden email] Subject: Re: Function Yes, that "edge case" occurred to me too. So something like this, maybe: new file. dataset close all. DATA LIST list /v1 to v3 (3f5.0). BEGIN DATA 1 2 3 3 4 5 7 8 9 1 3 5 2 4 6 3 5 7 4 6 8 5 7 9 5 3 999 5 999 999 999 999 999 END DATA. *MISSING VALUES all(999).* COMPUTE SumVars = SUM(v1 to v3). NUMERIC Product(f8.0). *DO IF nvalid(v1 to v3) GT 0*. /* There is at least one valid value. - COMPUTE Product=1. - DO REPEAT v = v1 to v3. - IF NOT MISSING(v) Product = Product*v. - END REPEAT. *END IF*. FORMATS SumVars(f8.0). LIST. OUTPUT: v1 v2 v3 SumVars Product 1 2 3 6 6 3 4 5 12 60 7 8 9 24 504 1 3 5 9 15 2 4 6 12 48 3 5 7 15 105 4 6 8 18 192 5 7 9 21 315 5 3 999 8 15 5 999 999 5 5 999 999 999 . . Jon K Peck wrote > There is an edge case with David's solution: > > And to mimic the treatment of missing values: > replace: Compute product ... with > IF NOT MISSING(x) Product=Product * x. > > If all the x's are missing, the result is 1, the initial value, instead of > missing so the all missing case should be checked. > > > > Jon Peck (no "h") aka Kim > Senior Software Engineer, IBM > peck@.ibm > phone: 720-342-5621 > > > > > From: Bruce Weaver < > bruce.weaver@ > > > To: > SPSSX-L@.uga > , > Date: 10/04/2013 07:11 AM > Subject: Re: [SPSSX-L] Function > Sent by: "SPSSX(r) Discussion" < > SPSSX-L@.uga > > > > > > D'oh! Yes...that is far more direct that the "Rubish" method I posted > (using > sums of logs etc) and then promptly deleted from the Nabble archive...but > not before it reached the archives at UGA, unfortunately. > > > > Maguin, Eugene wrote >> No function, not that I recall seeing. >> But: >> >> Compute product=1. >> Do repeat x=v1 to v(n). >> Compute product=product*x. >> End repeat. >> >> Gene Maguin >> >> -----Original Message----- >> From: SPSSX(r) Discussion [mailto: > >> SPSSX-L@.UGA > >> ] On Behalf Of drfg2008 >> Sent: Friday, October 04, 2013 6:13 AM >> To: > >> SPSSX-L@.UGA > >> Subject: Function >> >> probably a simple question, but I could not find an answer >> >> for the sum of variables SPSS provides SUM(v1 to vN). >> >> What about the multiplication? v1 * v2 * ... v(n-1) * v(n). >> >> >> >> >> >> ----- >> Dr. Frank Gaeth >> FU-Berlin >> >> -- >> View this message in context: >> http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368.html >> Sent from the SPSSX Discussion mailing list archive at Nabble.com. >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (not to SPSSX-L), with no body text except the command. To leave the >> list, send the command SIGNOFF SPSSX-L For a list of commands to manage >> subscriptions, send the command INFO REFCARD >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (not to SPSSX-L), with no body text except the >> command. To leave the list, send the command >> SIGNOFF SPSSX-L >> For a list of commands to manage subscriptions, send the command >> INFO REFCARD > > > > > > ----- > -- > Bruce Weaver > bweaver@ > http://sites.google.com/a/lakeheadu.ca/bweaver/ > > "When all else fails, RTFM." > > NOTE: My Hotmail account is not monitored regularly. > To send me an e-mail, please use the address shown above. > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722374.html > > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722382.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
Good idea, Brian, although I would not include recoding sysmis to 999 and making 999 a missing value part of the macro. What if 999 is a legitimate value? It would also be nice to have SumVar and ProductVar as macro arguments so that users can assign their own variable names. Something like this, maybe:
* Modification of Brian's macro to sum and multiply * a series of contiguous variables. PRESERVE. set printback=off mprint=off. DEFINE smvars (v1=!charend('/')/vN=!charend('/')/SumVar=!charend('/')/ProductVar = !CMDEND). COMPUTE !SumVar = SUM(!v1 to !vN). NUMERIC !ProductVar(f8.2). DO IF nvalid(!v1 to !vN) GT 0 . /* There is at least one valid value. - COMPUTE !ProductVar=1. - DO REPEAT v = !v1 to !vN . - IF NOT MISSING(v) !ProductVar = !ProductVar*v . - END REPEAT. END IF . !ENDDEFINE. RESTORE. * Read in some test data including user-defined * and system missing values. new file. dataset close all. DATA LIST list /v1 to v3 (3f5.0). BEGIN DATA 1 2 3 3 4 5 7 8 9 5 3 999 5 999 999 999 999 999 5 3 . 5 . . . . . END DATA. MISSING VALUES all(999). /* Macro Call Line . */ smvars v1=v1 / vN=v3 / SumVar=SumOfVars / ProductVar=ProductOfVars . LIST. Output: v1 v2 v3 SumOfVars ProductOfVars 1 2 3 6.00 6.00 3 4 5 12.00 60.00 7 8 9 24.00 504.00 5 3 999 8.00 15.00 5 999 999 5.00 5.00 999 999 999 . . 5 3 . 8.00 15.00 5 . . 5.00 5.00 . . . . . Cheers, Bruce
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Perfect!
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver Sent: Friday, October 04, 2013 2:31 PM To: [hidden email] Subject: Re: Function Good idea, Brian, although I would not include recoding sysmis to 999 and making 999 a missing value part of the macro. What if 999 is a legitimate value? It would also be nice to have SumVar and ProductVar as macro arguments so that users can assign their own variable names. Something like this, maybe: * Modification of Brian's macro to sum and multiply * a series of contiguous variables. PRESERVE. set printback=off mprint=off. DEFINE smvars (v1=!charend('/')/vN=!charend('/')/SumVar=!charend('/')/ProductVar = !CMDEND). COMPUTE !SumVar = SUM(!v1 to !vN). NUMERIC !ProductVar(f8.2). DO IF nvalid(!v1 to !vN) GT 0 . /* There is at least one valid value. - COMPUTE !ProductVar=1. - DO REPEAT v = !v1 to !vN . - IF NOT MISSING(v) !ProductVar = !ProductVar*v . - END REPEAT. END IF . !ENDDEFINE. RESTORE. * Read in some test data including user-defined * and system missing values. new file. dataset close all. DATA LIST list /v1 to v3 (3f5.0). BEGIN DATA 1 2 3 3 4 5 7 8 9 5 3 999 5 999 999 999 999 999 5 3 . 5 . . . . . END DATA. MISSING VALUES all(999). /* Macro Call Line . */ smvars v1=v1 / vN=v3 / SumVar=SumOfVars / ProductVar=ProductOfVars . LIST. Output: v1 v2 v3 SumOfVars ProductOfVars 1 2 3 6.00 6.00 3 4 5 12.00 60.00 7 8 9 24.00 504.00 5 3 999 8.00 15.00 5 999 999 5.00 5.00 999 999 999 . . 5 3 . 8.00 15.00 5 . . 5.00 5.00 . . . . . Cheers, Bruce bdates wrote > Bruce, I took the liberty of including your syntax in a macro so multiple > replacements wouldn't be necessary. I also added a replacement of missing > data with 999. I know it's a no-no to leave cells empty, but in our > experience, groups whose data we analyze don't always use a code for > missing. The macro presumes your data. > > preserve. > set printback=off mprint=off. > define smvars (var1=!charend('/')/varn=!charend('/')). > do repeat v=!var1 to !varn . > if missing(v) v=999 . > end repeat . > execute . > missing values all(999) . > COMPUTE SumVars = SUM(!var1 to !varn). > NUMERIC Product(f8.0). > DO IF nvalid(!var1 to !varn) GT 0 . /* There is at least one valid value. > - COMPUTE Product=1. > - DO REPEAT v = !var1 to !varn . > - IF NOT MISSING(v) Product = Product*v . > - END REPEAT. > END IF . > FORMATS SumVars(f8.0). > LIST. > !enddefine. > restore. > > /* Macro Call Line . > */ > > smvars var1=v1/varn=v3 . > > -----Original Message----- > From: SPSSX(r) Discussion [mailto: > SPSSX-L@.UGA > ] On Behalf Of Bruce Weaver > Sent: Friday, October 04, 2013 11:56 AM > To: > SPSSX-L@.UGA > Subject: Re: Function > > Yes, that "edge case" occurred to me too. So something like this, maybe: > > new file. > dataset close all. > > DATA LIST list /v1 to v3 (3f5.0). > BEGIN DATA > 1 2 3 > 3 4 5 > 7 8 9 > 1 3 5 > 2 4 6 > 3 5 7 > 4 6 8 > 5 7 9 > 5 3 999 > 5 999 999 > 999 999 999 > END DATA. > > *MISSING VALUES all(999).* > > COMPUTE SumVars = SUM(v1 to v3). > NUMERIC Product(f8.0). > *DO IF nvalid(v1 to v3) GT 0*. /* There is at least one valid value. > - COMPUTE Product=1. > - DO REPEAT v = v1 to v3. > - IF NOT MISSING(v) Product = Product*v. > - END REPEAT. > *END IF*. > FORMATS SumVars(f8.0). > LIST. > > OUTPUT: > v1 v2 v3 SumVars Product > 1 2 3 6 6 > 3 4 5 12 60 > 7 8 9 24 504 > 1 3 5 9 15 > 2 4 6 12 48 > 3 5 7 15 105 > 4 6 8 18 192 > 5 7 9 21 315 > 5 3 999 8 15 > 5 999 999 5 5 > 999 999 999 . . > > > > Jon K Peck wrote >> There is an edge case with David's solution: >> >> And to mimic the treatment of missing values: >> replace: Compute product ... with >> IF NOT MISSING(x) Product=Product * x. >> >> If all the x's are missing, the result is 1, the initial value, instead >> of >> missing so the all missing case should be checked. >> >> >> >> Jon Peck (no "h") aka Kim >> Senior Software Engineer, IBM > >> peck@.ibm > >> phone: 720-342-5621 >> >> >> >> >> From: Bruce Weaver < > >> bruce.weaver@ > >> > >> To: > >> SPSSX-L@.uga > >> , >> Date: 10/04/2013 07:11 AM >> Subject: Re: [SPSSX-L] Function >> Sent by: "SPSSX(r) Discussion" < > >> SPSSX-L@.uga > >> > >> >> >> >> D'oh! Yes...that is far more direct that the "Rubish" method I posted >> (using >> sums of logs etc) and then promptly deleted from the Nabble archive...but >> not before it reached the archives at UGA, unfortunately. >> >> >> >> Maguin, Eugene wrote >>> No function, not that I recall seeing. >>> But: >>> >>> Compute product=1. >>> Do repeat x=v1 to v(n). >>> Compute product=product*x. >>> End repeat. >>> >>> Gene Maguin >>> >>> -----Original Message----- >>> From: SPSSX(r) Discussion [mailto: >> >>> SPSSX-L@.UGA >> >>> ] On Behalf Of drfg2008 >>> Sent: Friday, October 04, 2013 6:13 AM >>> To: >> >>> SPSSX-L@.UGA >> >>> Subject: Function >>> >>> probably a simple question, but I could not find an answer >>> >>> for the sum of variables SPSS provides SUM(v1 to vN). >>> >>> What about the multiplication? v1 * v2 * ... v(n-1) * v(n). >>> >>> >>> >>> >>> >>> ----- >>> Dr. Frank Gaeth >>> FU-Berlin >>> >>> -- >>> View this message in context: >>> http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368.html >>> Sent from the SPSSX Discussion mailing list archive at Nabble.com. >>> >>> ===================== >>> To manage your subscription to SPSSX-L, send a message to >> >>> LISTSERV@.UGA >> >>> (not to SPSSX-L), with no body text except the command. To leave the >>> list, send the command SIGNOFF SPSSX-L For a list of commands to manage >>> subscriptions, send the command INFO REFCARD >>> >>> ===================== >>> To manage your subscription to SPSSX-L, send a message to >> >>> LISTSERV@.UGA >> >>> (not to SPSSX-L), with no body text except the >>> command. To leave the list, send the command >>> SIGNOFF SPSSX-L >>> For a list of commands to manage subscriptions, send the command >>> INFO REFCARD >> >> >> >> >> >> ----- >> -- >> Bruce Weaver > >> bweaver@ > >> http://sites.google.com/a/lakeheadu.ca/bweaver/ >> >> "When all else fails, RTFM." >> >> NOTE: My Hotmail account is not monitored regularly. >> To send me an e-mail, please use the address shown above. >> >> -- >> View this message in context: >> http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722374.html >> >> Sent from the SPSSX Discussion mailing list archive at Nabble.com. >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (not to SPSSX-L), with no body text except the >> command. To leave the list, send the command >> SIGNOFF SPSSX-L >> For a list of commands to manage subscriptions, send the command >> INFO REFCARD > > > > > > ----- > -- > Bruce Weaver > bweaver@ > http://sites.google.com/a/lakeheadu.ca/bweaver/ > > "When all else fails, RTFM." > > NOTE: My Hotmail account is not monitored regularly. > To send me an e-mail, please use the address shown above. > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722382.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722385.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Bruce Weaver
I know I'm being compulsive, but what the heck, put the missing value into the macro, too. Those four lines would look like:
DEFINE smvars (missval=!charend('/')/v1=!charend('/')/vN=!charend('/')/SumVar=!charend('/')/ProductVar = !CMDEND). MISSING VALUES all(!missval). ...and the call line would be: smvars missval=999 /v1=v1 / vN=v3 / SumVar=Sum_Of_Variables / ProductVar=Product_Of_Variables . -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver Sent: Friday, October 04, 2013 2:31 PM To: [hidden email] Subject: Re: Function Good idea, Brian, although I would not include recoding sysmis to 999 and making 999 a missing value part of the macro. What if 999 is a legitimate value? It would also be nice to have SumVar and ProductVar as macro arguments so that users can assign their own variable names. Something like this, maybe: * Modification of Brian's macro to sum and multiply * a series of contiguous variables. PRESERVE. set printback=off mprint=off. DEFINE smvars (v1=!charend('/')/vN=!charend('/')/SumVar=!charend('/')/ProductVar = !CMDEND). COMPUTE !SumVar = SUM(!v1 to !vN). NUMERIC !ProductVar(f8.2). DO IF nvalid(!v1 to !vN) GT 0 . /* There is at least one valid value. - COMPUTE !ProductVar=1. - DO REPEAT v = !v1 to !vN . - IF NOT MISSING(v) !ProductVar = !ProductVar*v . - END REPEAT. END IF . !ENDDEFINE. RESTORE. * Read in some test data including user-defined * and system missing values. new file. dataset close all. DATA LIST list /v1 to v3 (3f5.0). BEGIN DATA 1 2 3 3 4 5 7 8 9 5 3 999 5 999 999 999 999 999 5 3 . 5 . . . . . END DATA. MISSING VALUES all(999). /* Macro Call Line . */ smvars v1=v1 / vN=v3 / SumVar=SumOfVars / ProductVar=ProductOfVars . LIST. Output: v1 v2 v3 SumOfVars ProductOfVars 1 2 3 6.00 6.00 3 4 5 12.00 60.00 7 8 9 24.00 504.00 5 3 999 8.00 15.00 5 999 999 5.00 5.00 999 999 999 . . 5 3 . 8.00 15.00 5 . . 5.00 5.00 . . . . . Cheers, Bruce bdates wrote > Bruce, I took the liberty of including your syntax in a macro so multiple > replacements wouldn't be necessary. I also added a replacement of missing > data with 999. I know it's a no-no to leave cells empty, but in our > experience, groups whose data we analyze don't always use a code for > missing. The macro presumes your data. > > preserve. > set printback=off mprint=off. > define smvars (var1=!charend('/')/varn=!charend('/')). > do repeat v=!var1 to !varn . > if missing(v) v=999 . > end repeat . > execute . > missing values all(999) . > COMPUTE SumVars = SUM(!var1 to !varn). > NUMERIC Product(f8.0). > DO IF nvalid(!var1 to !varn) GT 0 . /* There is at least one valid value. > - COMPUTE Product=1. > - DO REPEAT v = !var1 to !varn . > - IF NOT MISSING(v) Product = Product*v . > - END REPEAT. > END IF . > FORMATS SumVars(f8.0). > LIST. > !enddefine. > restore. > > /* Macro Call Line . > */ > > smvars var1=v1/varn=v3 . > > -----Original Message----- > From: SPSSX(r) Discussion [mailto: > SPSSX-L@.UGA > ] On Behalf Of Bruce Weaver > Sent: Friday, October 04, 2013 11:56 AM > To: > SPSSX-L@.UGA > Subject: Re: Function > > Yes, that "edge case" occurred to me too. So something like this, maybe: > > new file. > dataset close all. > > DATA LIST list /v1 to v3 (3f5.0). > BEGIN DATA > 1 2 3 > 3 4 5 > 7 8 9 > 1 3 5 > 2 4 6 > 3 5 7 > 4 6 8 > 5 7 9 > 5 3 999 > 5 999 999 > 999 999 999 > END DATA. > > *MISSING VALUES all(999).* > > COMPUTE SumVars = SUM(v1 to v3). > NUMERIC Product(f8.0). > *DO IF nvalid(v1 to v3) GT 0*. /* There is at least one valid value. > - COMPUTE Product=1. > - DO REPEAT v = v1 to v3. > - IF NOT MISSING(v) Product = Product*v. > - END REPEAT. > *END IF*. > FORMATS SumVars(f8.0). > LIST. > > OUTPUT: > v1 v2 v3 SumVars Product > 1 2 3 6 6 > 3 4 5 12 60 > 7 8 9 24 504 > 1 3 5 9 15 > 2 4 6 12 48 > 3 5 7 15 105 > 4 6 8 18 192 > 5 7 9 21 315 > 5 3 999 8 15 > 5 999 999 5 5 > 999 999 999 . . > > > > Jon K Peck wrote >> There is an edge case with David's solution: >> >> And to mimic the treatment of missing values: >> replace: Compute product ... with >> IF NOT MISSING(x) Product=Product * x. >> >> If all the x's are missing, the result is 1, the initial value, instead >> of >> missing so the all missing case should be checked. >> >> >> >> Jon Peck (no "h") aka Kim >> Senior Software Engineer, IBM > >> peck@.ibm > >> phone: 720-342-5621 >> >> >> >> >> From: Bruce Weaver < > >> bruce.weaver@ > >> > >> To: > >> SPSSX-L@.uga > >> , >> Date: 10/04/2013 07:11 AM >> Subject: Re: [SPSSX-L] Function >> Sent by: "SPSSX(r) Discussion" < > >> SPSSX-L@.uga > >> > >> >> >> >> D'oh! Yes...that is far more direct that the "Rubish" method I posted >> (using >> sums of logs etc) and then promptly deleted from the Nabble archive...but >> not before it reached the archives at UGA, unfortunately. >> >> >> >> Maguin, Eugene wrote >>> No function, not that I recall seeing. >>> But: >>> >>> Compute product=1. >>> Do repeat x=v1 to v(n). >>> Compute product=product*x. >>> End repeat. >>> >>> Gene Maguin >>> >>> -----Original Message----- >>> From: SPSSX(r) Discussion [mailto: >> >>> SPSSX-L@.UGA >> >>> ] On Behalf Of drfg2008 >>> Sent: Friday, October 04, 2013 6:13 AM >>> To: >> >>> SPSSX-L@.UGA >> >>> Subject: Function >>> >>> probably a simple question, but I could not find an answer >>> >>> for the sum of variables SPSS provides SUM(v1 to vN). >>> >>> What about the multiplication? v1 * v2 * ... v(n-1) * v(n). >>> >>> >>> >>> >>> >>> ----- >>> Dr. Frank Gaeth >>> FU-Berlin >>> >>> -- >>> View this message in context: >>> http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368.html >>> Sent from the SPSSX Discussion mailing list archive at Nabble.com. >>> >>> ===================== >>> To manage your subscription to SPSSX-L, send a message to >> >>> LISTSERV@.UGA >> >>> (not to SPSSX-L), with no body text except the command. To leave the >>> list, send the command SIGNOFF SPSSX-L For a list of commands to manage >>> subscriptions, send the command INFO REFCARD >>> >>> ===================== >>> To manage your subscription to SPSSX-L, send a message to >> >>> LISTSERV@.UGA >> >>> (not to SPSSX-L), with no body text except the >>> command. To leave the list, send the command >>> SIGNOFF SPSSX-L >>> For a list of commands to manage subscriptions, send the command >>> INFO REFCARD >> >> >> >> >> >> ----- >> -- >> Bruce Weaver > >> bweaver@ > >> http://sites.google.com/a/lakeheadu.ca/bweaver/ >> >> "When all else fails, RTFM." >> >> NOTE: My Hotmail account is not monitored regularly. >> To send me an e-mail, please use the address shown above. >> >> -- >> View this message in context: >> http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722374.html >> >> Sent from the SPSSX Discussion mailing list archive at Nabble.com. >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (not to SPSSX-L), with no body text except the >> command. To leave the list, send the command >> SIGNOFF SPSSX-L >> For a list of commands to manage subscriptions, send the command >> INFO REFCARD > > > > > > ----- > -- > Bruce Weaver > bweaver@ > http://sites.google.com/a/lakeheadu.ca/bweaver/ > > "When all else fails, RTFM." > > NOTE: My Hotmail account is not monitored regularly. > To send me an e-mail, please use the address shown above. > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722382.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Function-tp5722368p5722385.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Perhaps I am just tired
at the end of the week.
I understand the arithmetic of the product of the elements in a vector. Often symbolized by a capital Greek P (Pi). What what practical application is there where the vector would include missing values? Art Kendall Social Research ConsultantsOn 10/4/2013 4:05 PM, bdates [via SPSSX Discussion] wrote: I know I'm being compulsive, but what the heck, put the missing value into the macro, too. Those four lines would look like:
Art Kendall
Social Research Consultants |
Art,
Good catch! I've been wondering too since any product with less than the same number of vectors as the majority of other products would be 'meaningless'. However I'm not sure what the intent of the post was. I think we can rewrite the syntax to exclude
any cases in which data are missing. Hopefully the 'poster' will let us know so we might proceed.
Brian
From: SPSSX(r) Discussion [[hidden email]] on behalf of Art Kendall [[hidden email]]
Sent: Friday, October 04, 2013 4:17 PM To: [hidden email] Subject: Re: Function Perhaps I am just tired at the end of the week.
I understand the arithmetic of the product of the elements in a vector. Often symbolized by a capital Greek P (Pi). What what practical application is there where the vector would include missing values? Art Kendall Social Research ConsultantsOn 10/4/2013 4:05 PM, bdates [via SPSSX Discussion] wrote: I know I'm being compulsive, but what the heck, put the missing value into the macro, too. Those four lines would look like: Art Kendall
Social Research Consultants View this message in context: Re: Function Sent from the SPSSX Discussion mailing list archive at Nabble.com. |
Free forum by Nabble | Edit this page |