# Odd Vector Behavior

8 messages
Open this post in threaded view
|

## Odd Vector Behavior

 I have the following syntax: GET FILE 'SUBDIR\Referencefile'. select if casenum le 10. string title (a403) / journal (a201) / author (a302). string allvars (a1069). string line1 (a80) / line2 to line14 (a70) / space (a10). compute title=concat(ltrim(rtrim(title1)),' ',ltrim(rtrim(title2)),' ',ltrim(rtrim(title3)),' ',ltrim(rtrim(title4))). compute author=concat(ltrim(rtrim(author1)),' ',ltrim(rtrim(author2)),' ',ltrim(rtrim(author3))). compute journal=concat(ltrim(rtrim(journal1)),' ',ltrim(rtrim(journal2))). compute allvars=concat(rtrim(author),', ',rtrim(year),' ',rtrim(month),', "',rtrim(title),'", ',                         rtrim(citation),', ',rtrim(string(casenum,f5))). compute line1 = substr(allvars,1,80). vector line = line2 to line14. loop #i=2 to 14.      compute line(#i) = substr(allvars,((10+#i*70+1)-70),70). end loop. When I run this program I get the following warning mesage for each case: Warning # 520 The subscript of a string vector is missing, out of range, or not an integer. The result will be a reference to a string of length 0. Command line: 346  Current case: 3  Current splitfile group: 1 The only way this program will work is if I change the string command from string line2 to line14 (a70) to string line2 to line15 (a70) and change the vector command from vector line = line2 to line14. to vector line = line2 to line15. Even though the loop goes from 2 to 14 and never goes to 15,  I need to create another variable, line15, that I will never use and declare it in the vector command. Can anyone explain this? I have rebooted the computer with the same result. I also thought that the variable, line1, might somehow be confusing the vector command and so I changed the name of this variable but I still got the same result. Stan ===================== 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
Open this post in threaded view
|

## Re: Odd Vector Behavior

 Your loop is starting with the second element of the vector line, which is line3.  The vector declaration covers line2, line3, ... line14, which is 13 variables, so line(14) is out of range,On Sat, May 13, 2017 at 6:26 PM, Stan Gorodenski wrote:I have the following syntax: GET FILE 'SUBDIR\Referencefile'. select if casenum le 10. string title (a403) / journal (a201) / author (a302). string allvars (a1069). string line1 (a80) / line2 to line14 (a70) / space (a10). compute title=concat(ltrim(rtrim(title1)),' ',ltrim(rtrim(title2)),' ',ltrim(rtrim(title3)),' ',ltrim(rtrim(title4))). compute author=concat(ltrim(rtrim(author1)),' ',ltrim(rtrim(author2)),' ',ltrim(rtrim(author3))). compute journal=concat(ltrim(rtrim(journal1)),' ',ltrim(rtrim(journal2))). compute allvars=concat(rtrim(author),', ',rtrim(year),' ',rtrim(month),', "',rtrim(title),'", ',                        rtrim(citation),', ',rtrim(string(casenum,f5))). compute line1 = substr(allvars,1,80). vector line = line2 to line14. loop #i=2 to 14.     compute line(#i) = substr(allvars,((10+#i*70+1)-70),70). end loop. When I run this program I get the following warning mesage for each case: Warning # 520 The subscript of a string vector is missing, out of range, or not an integer. The result will be a reference to a string of length 0. Command line: 346  Current case: 3  Current splitfile group: 1 The only way this program will work is if I change the string command from string line2 to line14 (a70) to string line2 to line15 (a70) and change the vector command from vector line = line2 to line14. to vector line = line2 to line15. Even though the loop goes from 2 to 14 and never goes to 15,  I need to create another variable, line15, that I will never use and declare it in the vector command. Can anyone explain this? I have rebooted the computer with the same result. I also thought that the variable, line1, might somehow be confusing the vector command and so I changed the name of this variable but I still got the same result. Stan ===================== 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 -- Jon K Peck[hidden email] ===================== 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
Open this post in threaded view
|

## Re: Odd Vector Behavior

 I'm afraid I don't understand it. The loop goes from #i=2 to 14 which is 13 loops. Thirteen vector variables are created within the loop based on the value of #i and they all were previously defined by the vector definition. The first vector variable created is line(2), the last is line(14). There are thirteen vector variables and so the number of vector variables matches the number of loops. When I define the vector to be vector line=line2 to line14. it is the same as vector line=line2 line3 line3 ... line14. When you say the vector starts with the second element of the vector line, is the second element line3? If this is the case, then what it is saying, to me, is that when vector variables are being created within a loop, the numeric values that define the number of loops is linked to a position in the vector declaration. Is this true? If it is it seems odd to me because why would the number of iterations in a loop have to correspond to the number of vector variables being defined when no new vector variables are being created that were not defined in the vector statement? Stan On 5/13/2017 8:17 PM, Jon Peck wrote: > Your loop is starting with the second element of the vector line, > which is line3.  The vector declaration covers line2, line3, ... > line14, which is 13 variables, so line(14) is out of range, > > On Sat, May 13, 2017 at 6:26 PM, Stan Gorodenski > <[hidden email] > wrote: > >     I have the following syntax: > > >     GET FILE 'SUBDIR\Referencefile'. >     select if casenum le 10. >     string title (a403) / journal (a201) / author (a302). >     string allvars (a1069). >     string line1 (a80) / line2 to line14 (a70) / space (a10). > >     compute title=concat(ltrim(rtrim(title1)),' >     ',ltrim(rtrim(title2)),' ',ltrim(rtrim(title3)),' >     ',ltrim(rtrim(title4))). >     compute author=concat(ltrim(rtrim(author1)),' >     ',ltrim(rtrim(author2)),' ',ltrim(rtrim(author3))). >     compute journal=concat(ltrim(rtrim(journal1)),' >     ',ltrim(rtrim(journal2))). >     compute allvars=concat(rtrim(author),', ',rtrim(year),' >     ',rtrim(month),', "',rtrim(title),'", ', >                            rtrim(citation),', >     ',rtrim(string(casenum,f5))). > >     compute line1 = substr(allvars,1,80). >     vector line = line2 to line14. >     loop #i=2 to 14. >         compute line(#i) = substr(allvars,((10+#i*70+1)-70),70). >     end loop. > > >     When I run this program I get the following warning mesage for >     each case: >     Warning # 520 >     The subscript of a string vector is missing, out of range, or not >     an integer. >     The result will be a reference to a string of length 0. >     Command line: 346  Current case: 3  Current splitfile group: 1 > > >     The only way this program will work is if I change the string >     command from >     string line2 to line14 (a70) >     to >     string line2 to line15 (a70) > >     and change the vector command from >     vector line = line2 to line14. >     to >     vector line = line2 to line15. > >     Even though the loop goes from 2 to 14 and never goes to 15,  I >     need to create another variable, line15, that I will never use and >     declare it in the vector command. Can anyone explain this? I have >     rebooted the computer with the same result. I also thought that >     the variable, line1, might somehow be confusing the vector command >     and so I changed the name of this variable but I still got the >     same result. >     Stan > >     ===================== >     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 > > > > > -- > Jon K Peck > [hidden email] > > ===================== 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
Open this post in threaded view
|

## Re: Odd Vector Behavior

 Stan, Your mistake is that you may be confusing in perception the inde[ in the var name (e.g. "line2") with its index (position) in the vector (e.g. "line(2)") Use vector line = line1 to line14. instead of vector line = line2 to line14. Note that all string vars from line1 to line 2 must be of the same width, so create line1 of width 70, too, not of width 80. 14.05.2017 7:31, Stan Gorodenski пишет: I'm afraid I don't understand it. The loop goes from #i=2 to 14 which is 13 loops. Thirteen vector variables are created within the loop based on the value of #i and they all were previously defined by the vector definition. The first vector variable created is line(2), the last is line(14). There are thirteen vector variables and so the number of vector variables matches the number of loops. When I define the vector to be vector line=line2 to line14. it is the same as vector line=line2 line3 line3 ... line14. When you say the vector starts with the second element of the vector line, is the second element line3? If this is the case, then what it is saying, to me, is that when vector variables are being created within a loop, the numeric values that define the number of loops is linked to a position in the vector declaration. Is this true? If it is it seems odd to me because why would the number of iterations in a loop have to correspond to the number of vector variables being defined when no new vector variables are being created that were not defined in the vector statement? Stan On 5/13/2017 8:17 PM, Jon Peck wrote: Your loop is starting with the second element of the vector line, which is line3.  The vector declaration covers line2, line3, ... line14, which is 13 variables, so line(14) is out of range, On Sat, May 13, 2017 at 6:26 PM, Stan Gorodenski <[hidden email] [hidden email]> wrote:     I have the following syntax:     GET FILE 'SUBDIR\Referencefile'.     select if casenum le 10.     string title (a403) / journal (a201) / author (a302).     string allvars (a1069).     string line1 (a80) / line2 to line14 (a70) / space (a10).     compute title=concat(ltrim(rtrim(title1)),'     ',ltrim(rtrim(title2)),' ',ltrim(rtrim(title3)),'     ',ltrim(rtrim(title4))).     compute author=concat(ltrim(rtrim(author1)),'     ',ltrim(rtrim(author2)),' ',ltrim(rtrim(author3))).     compute journal=concat(ltrim(rtrim(journal1)),'     ',ltrim(rtrim(journal2))).     compute allvars=concat(rtrim(author),', ',rtrim(year),'     ',rtrim(month),', "',rtrim(title),'", ',                            rtrim(citation),',     ',rtrim(string(casenum,f5))).     compute line1 = substr(allvars,1,80).     vector line = line2 to line14.     loop #i=2 to 14.         compute line(#i) = substr(allvars,((10+#i*70+1)-70),70).     end loop.     When I run this program I get the following warning mesage for     each case:     Warning # 520     The subscript of a string vector is missing, out of range, or not     an integer.     The result will be a reference to a string of length 0.     Command line: 346  Current case: 3  Current splitfile group: 1     The only way this program will work is if I change the string     command from     string line2 to line14 (a70)     to     string line2 to line15 (a70)     and change the vector command from     vector line = line2 to line14.     to     vector line = line2 to line15.     Even though the loop goes from 2 to 14 and never goes to 15,  I     need to create another variable, line15, that I will never use and     declare it in the vector command. Can anyone explain this? I have     rebooted the computer with the same result. I also thought that     the variable, line1, might somehow be confusing the vector command     and so I changed the name of this variable but I still got the     same result.     Stan     =====================     To manage your subscription to SPSSX-L, send a message to     [hidden email] [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 --  Jon K Peck [hidden email] [hidden email] ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] [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
Open this post in threaded view
|

## Re: Odd Vector Behavior

 Stan, Your mistake is that you may be confusing in perception the index in the var name (e.g. "line2") with its index (position) in the vector (e.g. "line(2)") Use vector line = line1 to line14. instead of vector line = line2 to line14. Note that all string vars from line1 to line14 must be of the same width, so create line1 of width 70, too, not of width 80. 14.05.2017 8:21, Kirill Orlov пишет: Stan, Your mistake is that you may be confusing in perception the inde[ in the var name (e.g. "line2") with its index (position) in the vector (e.g. "line(2)") Use vector line = line1 to line14. instead of vector line = line2 to line14. Note that all string vars from line1 to line 2 must be of the same width, so create line1 of width 70, too, not of width 80. 14.05.2017 7:31, Stan Gorodenski пишет: I'm afraid I don't understand it. The loop goes from #i=2 to 14 which is 13 loops. Thirteen vector variables are created within the loop based on the value of #i and they all were previously defined by the vector definition. The first vector variable created is line(2), the last is line(14). There are thirteen vector variables and so the number of vector variables matches the number of loops. When I define the vector to be vector line=line2 to line14. it is the same as vector line=line2 line3 line3 ... line14. When you say the vector starts with the second element of the vector line, is the second element line3? If this is the case, then what it is saying, to me, is that when vector variables are being created within a loop, the numeric values that define the number of loops is linked to a position in the vector declaration. Is this true? If it is it seems odd to me because why would the number of iterations in a loop have to correspond to the number of vector variables being defined when no new vector variables are being created that were not defined in the vector statement? Stan On 5/13/2017 8:17 PM, Jon Peck wrote: Your loop is starting with the second element of the vector line, which is line3.  The vector declaration covers line2, line3, ... line14, which is 13 variables, so line(14) is out of range, On Sat, May 13, 2017 at 6:26 PM, Stan Gorodenski <[hidden email] [hidden email]> wrote:     I have the following syntax:     GET FILE 'SUBDIR\Referencefile'.     select if casenum le 10.     string title (a403) / journal (a201) / author (a302).     string allvars (a1069).     string line1 (a80) / line2 to line14 (a70) / space (a10).     compute title=concat(ltrim(rtrim(title1)),'     ',ltrim(rtrim(title2)),' ',ltrim(rtrim(title3)),'     ',ltrim(rtrim(title4))).     compute author=concat(ltrim(rtrim(author1)),'     ',ltrim(rtrim(author2)),' ',ltrim(rtrim(author3))).     compute journal=concat(ltrim(rtrim(journal1)),'     ',ltrim(rtrim(journal2))).     compute allvars=concat(rtrim(author),', ',rtrim(year),'     ',rtrim(month),', "',rtrim(title),'", ',                            rtrim(citation),',     ',rtrim(string(casenum,f5))).     compute line1 = substr(allvars,1,80).     vector line = line2 to line14.     loop #i=2 to 14.         compute line(#i) = substr(allvars,((10+#i*70+1)-70),70).     end loop.     When I run this program I get the following warning mesage for     each case:     Warning # 520     The subscript of a string vector is missing, out of range, or not     an integer.     The result will be a reference to a string of length 0.     Command line: 346  Current case: 3  Current splitfile group: 1     The only way this program will work is if I change the string     command from     string line2 to line14 (a70)     to     string line2 to line15 (a70)     and change the vector command from     vector line = line2 to line14.     to     vector line = line2 to line15.     Even though the loop goes from 2 to 14 and never goes to 15,  I     need to create another variable, line15, that I will never use and     declare it in the vector command. Can anyone explain this? I have     rebooted the computer with the same result. I also thought that     the variable, line1, might somehow be confusing the vector command     and so I changed the name of this variable but I still got the     same result.     Stan     =====================     To manage your subscription to SPSSX-L, send a message to     [hidden email] [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 --  Jon K Peck [hidden email] [hidden email] ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] [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
Open this post in threaded view
|

## Re: Odd Vector Behavior

 In reply to this post by Stan Gorodenski No, the first element of line() is line2 when you say Vector line= line1 to line14.  Since you set up the vector as line2 to line14, you have created the (undesirable) situation were the item referenced by line(1) - its first element - is line2.  Don't do that unless you want to plague yourself of some later maintainer with confusion and error.  If you /have/ to  do that, then use plenty of Comments to leave the clue. -- Rich Ulrich From: SPSSX(r) Discussion <[hidden email]> on behalf of Stan Gorodenski <[hidden email]> Sent: Sunday, May 14, 2017 12:31:42 AM To: [hidden email] Subject: Re: Odd Vector Behavior   I'm afraid I don't understand it. The loop goes from #i=2 to 14 which is 13 loops. Thirteen vector variables are created within the loop based on the value of #i and they all were previously defined by the vector definition. The first vector variable created is line(2), the last is line(14). There are thirteen vector variables and so the number of vector variables matches the number of loops. When I define the vector to be vector line=line2 to line14. it is the same as vector line=line2 line3 line3 ... line14. When you say the vector starts with the second element of the vector line, is the second element line3? If this is the case, then what it is saying, to me, is that when vector variables are being created within a loop, the numeric values that define the number of loops is linked to a position in the vector declaration. Is this true? If it is it seems odd to me because why would the number of iterations in a loop have to correspond to the number of vector variables being defined when no new vector variables are being created that were not defined in the vector statement? Stan On 5/13/2017 8:17 PM, Jon Peck wrote: > Your loop is starting with the second element of the vector line, > which is line3.  The vector declaration covers line2, line3, ... > line14, which is 13 variables, so line(14) is out of range, > > On Sat, May 13, 2017 at 6:26 PM, Stan Gorodenski > <[hidden email] <[hidden email]>> wrote: > >     I have the following syntax: > > >     GET FILE 'SUBDIR\Referencefile'. >     select if casenum le 10. >     string title (a403) / journal (a201) / author (a302). >     string allvars (a1069). >     string line1 (a80) / line2 to line14 (a70) / space (a10). > >     compute title=concat(ltrim(rtrim(title1)),' >     ',ltrim(rtrim(title2)),' ',ltrim(rtrim(title3)),' >     ',ltrim(rtrim(title4))). >     compute author=concat(ltrim(rtrim(author1)),' >     ',ltrim(rtrim(author2)),' ',ltrim(rtrim(author3))). >     compute journal=concat(ltrim(rtrim(journal1)),' >     ',ltrim(rtrim(journal2))). >     compute allvars=concat(rtrim(author),', ',rtrim(year),' >     ',rtrim(month),', "',rtrim(title),'", ', >                            rtrim(citation),', >     ',rtrim(string(casenum,f5))). > >     compute line1 = substr(allvars,1,80). >     vector line = line2 to line14. >     loop #i=2 to 14. >         compute line(#i) = substr(allvars,((10+#i*70+1)-70),70). >     end loop. > > >     When I run this program I get the following warning mesage for >     each case: >     Warning # 520 >     The subscript of a string vector is missing, out of range, or not >     an integer. >     The result will be a reference to a string of length 0. >     Command line: 346  Current case: 3  Current splitfile group: 1 > > >     The only way this program will work is if I change the string >     command from >     string line2 to line14 (a70) >     to >     string line2 to line15 (a70) > >     and change the vector command from >     vector line = line2 to line14. >     to >     vector line = line2 to line15. > >     Even though the loop goes from 2 to 14 and never goes to 15,  I >     need to create another variable, line15, that I will never use and >     declare it in the vector command. Can anyone explain this? I have >     rebooted the computer with the same result. I also thought that >     the variable, line1, might somehow be confusing the vector command >     and so I changed the name of this variable but I still got the >     same result. >     Stan > >     ===================== >     To manage your subscription to SPSSX-L, send a message to >     [hidden email] <[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 > > > > > -- > Jon K Peck > [hidden email] <[hidden email]> > > ===================== To manage your subscription to SPSSX-L, send a > message to [hidden email] > <[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