Happy New Year to all.
I would appreciate some assistance with changing the name of a Vector variable range in a Macro. If the number of statements & brands can vary I need a way to accomodate this in a macro loop. Example - If I have 4 statements & 4 brands I have a data file with 16 variables - S1B1,S1B2,S1B3,S1B4,S2B1........S4B4. I want to loop through a computation that defines 4 vectors ONE AT A TIME, for example Vector Stat = S1B1 to S1B4 and then Vector Stat = S2B1 to S2B4 and then Vector Stat = S3B1 to S3B4 and then Vector Stat = S4B1 to S4B4 [see my attempt below] What I can't get correct is the incrementing Sx. SEE LINE HIGHLIGHTED IB SYNTAX BELOW. Any pointers will be greatly appreciated. ####################################################################### My Syntax ################# **Number of brands ~ NBRANDS. **Number of statements~NSTATS. *****Define Macro************************. Define !Jac (NSTATS=!Tokens(1)/NBRANDS=!Tokens(1)). ******. Loop #s = 1 to !NSTATS. *******STATEMENT X ********. Compute Match=0. Compute NoMatch=0. exe. Vector Pct(!NSTATS). ***Change this line for each statement****. THIS IS THE LINE I'M STRUGGLING WITH.########## Vector Stat= !CONCAT('s',!NSTATS,'b1',' ','to',' ','s1','b',!NBRANDS). Loop #c = 1 to !Nbrands. If Stat(#c) = MainB Match=Match+1. If (Stat(#c)>0 & Stat(#c)<>MainB) NoMatch=NoMatch+1. End loop. *********************************. If (NoMatch=0 & Match=0) NoMatch=1. ***Results as percentages Range 0-100******************************. Compute Pct(#s) = (Match/(NoMatch+Match))*100. End loop. ************************. !Enddefine. ****Macro Call********************. !Jac NBRANDS=4 NSTATS=12. ************************. |
Hi,
It is not quite clear to me, but perhaps a !DO loop could help you. Something like !DO !N = 1 !TO !NSTATS Vector Stat= !CONCAT('s',!N,'b1',' ','to',' ','s',!N,'b',!NBRANDS). **** here the loop code. execute. !DOEND Happy New Year to you, Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mark Webb Sent: Tuesday, January 02, 2007 3:10 PM To: [hidden email] Subject: Looping in VECTOR ranges within a Macro Happy New Year to all. I would appreciate some assistance with changing the name of a Vector variable range in a Macro. If the number of statements & brands can vary I need a way to accomodate this in a macro loop. Example - If I have 4 statements & 4 brands I have a data file with 16 variables - S1B1,S1B2,S1B3,S1B4,S2B1........S4B4. I want to loop through a computation that defines 4 vectors ONE AT A TIME, for example Vector Stat = S1B1 to S1B4 and then Vector Stat = S2B1 to S2B4 and then Vector Stat = S3B1 to S3B4 and then Vector Stat = S4B1 to S4B4 [see my attempt below] What I can't get correct is the incrementing Sx. SEE LINE HIGHLIGHTED IB SYNTAX BELOW. Any pointers will be greatly appreciated. ####################################################################### My Syntax ################# **Number of brands ~ NBRANDS. **Number of statements~NSTATS. *****Define Macro************************. Define !Jac (NSTATS=!Tokens(1)/NBRANDS=!Tokens(1)). ******. Loop #s = 1 to !NSTATS. *******STATEMENT X ********. Compute Match=0. Compute NoMatch=0. exe. Vector Pct(!NSTATS). ***Change this line for each statement****. THIS IS THE LINE I'M STRUGGLING WITH.########## Vector Stat= !CONCAT('s',!NSTATS,'b1',' ','to',' ','s1','b',!NBRANDS). Loop #c = 1 to !Nbrands. If Stat(#c) = MainB Match=Match+1. If (Stat(#c)>0 & Stat(#c)<>MainB) NoMatch=NoMatch+1. End loop. *********************************. If (NoMatch=0 & Match=0) NoMatch=1. ***Results as percentages Range 0-100******************************. Compute Pct(#s) = (Match/(NoMatch+Match))*100. End loop. ************************. !Enddefine. ****Macro Call********************. !Jac NBRANDS=4 NSTATS=12. ************************. |
In reply to this post by Mark Webb-3
We have posted new versions of a few modules on SPSS Developer Central (www.spss.com/devcentral).
The spssaux.py module has a new property in the VariableDict class, MissingValues2 that provides a more convenient way of working with missing value specifications but requires SPSS 15.0.1. The spssaux2.py module now has a function called FindUnlabelledValues that does exactly that for a list of variables. It requires the newest version of the spssaux.py module but works with SPSS 14.0.1 or later. The DisplayDict.py module now has the ability to provide some basic codebook-like statistics along with the dictionary information. It can provide counts for categorical variable values and labeled values of scale variables and means and validn for scale variables. It can provide the counts for all variables if desired. Means are only available with SPSS 15.0.1. Regards, Jon Peck SPSS |
Good work, Jon, and thanks very much! I can't wait for someone to ask me how to find unlabelled values in a huge data file.
King > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of > Peck, Jon > Sent: Tuesday, January 02, 2007 8:52 AM > To: [hidden email] > Subject: Updated Python Items on Developer Central > > > We have posted new versions of a few modules on SPSS Developer > Central (www.spss.com/devcentral). > > The spssaux.py module has a new property in the VariableDict > class, MissingValues2 that provides a more convenient way of > working with missing value specifications but requires SPSS 15.0.1. > > The spssaux2.py module now has a function called > FindUnlabelledValues that does exactly that for a list of > variables. It requires the newest version of the spssaux.py > module but works with SPSS 14.0.1 or later. > > The DisplayDict.py module now has the ability to provide some > basic codebook-like statistics along with the dictionary > information. It can provide counts for categorical variable > values and labeled values of scale variables and means and validn > for scale variables. It can provide the counts for all > variables if desired. Means are only available with SPSS 15.0.1. > > Regards, > Jon Peck > SPSS |
Well, the best way to do that is with the Data Prep module (aka Data Validation), which includes unlabeled values as a potential rule violation to be applied to variables (along with many other rules and statistical criteria as well). But if you don't have that module, which was introduced with SPSS 14, this function will help.
- Jon -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of King Douglas Sent: Tuesday, January 02, 2007 10:23 AM To: [hidden email] Subject: Re: [SPSSX-L] Updated Python Items on Developer Central Good work, Jon, and thanks very much! I can't wait for someone to ask me how to find unlabelled values in a huge data file. King > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of > Peck, Jon > Sent: Tuesday, January 02, 2007 8:52 AM > To: [hidden email] > Subject: Updated Python Items on Developer Central > > > We have posted new versions of a few modules on SPSS Developer > Central (www.spss.com/devcentral). > > The spssaux.py module has a new property in the VariableDict > class, MissingValues2 that provides a more convenient way of > working with missing value specifications but requires SPSS 15.0.1. > > The spssaux2.py module now has a function called > FindUnlabelledValues that does exactly that for a list of > variables. It requires the newest version of the spssaux.py > module but works with SPSS 14.0.1 or later. > > The DisplayDict.py module now has the ability to provide some > basic codebook-like statistics along with the dictionary > information. It can provide counts for categorical variable > values and labeled values of scale variables and means and validn > for scale variables. It can provide the counts for all > variables if desired. Means are only available with SPSS 15.0.1. > > Regards, > Jon Peck > SPSS |
In reply to this post by Mark Webb-3
Hi Mark & the rest of the list,
Happy new year to you too! Did you consider using an index loop? Perhaps it's possible the way you describe it, but I'd have opted for do-to-doend-loop, as in: .... !do !i = 1 !to 4. !do !j = 1 !to 4. vector stat = !concat ('S',!i,'B',!j). .... .... .... !doend. !doend. !enddefine. Hope this helps, Albert-Jan --- Mark Webb <[hidden email]> wrote: > Happy New Year to all. > I would appreciate some assistance with changing the > name of a Vector variable range in a Macro. > If the number of statements & brands can vary I need > a way to accomodate this in a macro loop. > Example - If I have 4 statements & 4 brands I have a > data file with 16 variables - > S1B1,S1B2,S1B3,S1B4,S2B1........S4B4. > I want to loop through a computation that defines 4 > vectors ONE AT A TIME, for example > Vector Stat = S1B1 to S1B4 > and then > Vector Stat = S2B1 to S2B4 > and then > Vector Stat = S3B1 to S3B4 > and then > Vector Stat = S4B1 to S4B4 > [see my attempt below] > What I can't get correct is the incrementing Sx. SEE > LINE HIGHLIGHTED IB SYNTAX BELOW. > Any pointers will be greatly appreciated. > > > > My Syntax ################# > **Number of brands ~ NBRANDS. > > **Number of statements~NSTATS. > > *****Define Macro************************. > > Define !Jac (NSTATS=!Tokens(1)/NBRANDS=!Tokens(1)). > > ******. > > Loop #s = 1 to !NSTATS. > > *******STATEMENT X ********. > > Compute Match=0. > > Compute NoMatch=0. > > exe. > > Vector Pct(!NSTATS). > > ***Change this line for each statement****. THIS IS > THE LINE I'M STRUGGLING WITH.########## > > Vector Stat= !CONCAT('s',!NSTATS,'b1',' ','to',' > ','s1','b',!NBRANDS). > > Loop #c = 1 to !Nbrands. > > If Stat(#c) = MainB Match=Match+1. > > If (Stat(#c)>0 & Stat(#c)<>MainB) NoMatch=NoMatch+1. > > End loop. > > *********************************. > > If (NoMatch=0 & Match=0) NoMatch=1. > > ***Results as percentages Range > 0-100******************************. > > Compute Pct(#s) = (Match/(NoMatch+Match))*100. > > End loop. > > ************************. > > !Enddefine. > > ****Macro Call********************. > > !Jac NBRANDS=4 NSTATS=12. > > ************************. > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |
Free forum by Nabble | Edit this page |