Help With Loops and Vectors

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Help With Loops and Vectors

Feinstein, Zachary
STRING a(A175).

VECTOR a = a1 TO a15.

LOOP cnt = 1 TO 14.

- COMPUTE a = CONCAT(RTRIM(a),RTRIM(a(cnt)),"-").

END LOOP.

- COMPUTE a = CONCAT(RTRIM(a),a(15)).

EXECUTE.

 

The code above is what I use to combine 15 different strings for each
case in my dataset.  I places a "-" between each string.  Note- and I do
not know if this makes a difference- each of the strings has a different
length.

 

How may I modify the above code, or add to it, so that it does not give
all of the extra -s when many of the strings are blank.  For example,
many of the cases only have a string variable for the 15th one (the rest
are blank) so the resulting field has a bunch of -s followed by the
contents of a(15).  I would want that to just have the contents of a(15)
alone without all of the preceding -s.  The same logic would hopefully
apply for when maybe just a(5) has information in it and the rest is
blank.

 

Thank you.

 

Zachary

====================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
Reply | Threaded
Open this post in threaded view
|

Re: Help With Loops and Vectors

Maguin, Eugene
Zachary,

Well, how about testing whether the a(cnt) string is blank before
concantenating. In 16, I think I have seen a string function for that
purpose. If you don't like that, the Index or substring function may work,
depending on the structure of the a(cnt) strings. Assuming that a non-blank
a(cnt) string never has a space, ' ', character in column 1, the presence of
a space in column 1 means a blank string, which is then non concantenated.

The other thing I think might work is to concantenate the '-' character
before adding the second nonblank a(cnt) string. As written now, the '-' is
added following the a(cnt) string.

I haven't tested this out so there may be errors in my thinking but this is
how I'd start at the moment.

Gene Maguin


STRING a(A175).
VECTOR a = a1 TO a15.
LOOP cnt = 1 TO 14.
- COMPUTE a = CONCAT(RTRIM(a),RTRIM(a(cnt)),"-").
END LOOP.
- COMPUTE a = CONCAT(RTRIM(a),a(15)).
EXECUTE.

The code above is what I use to combine 15 different strings for each
case in my dataset.  I places a "-" between each string.  Note- and I do
not know if this makes a difference- each of the strings has a different
length.

How may I modify the above code, or add to it, so that it does not give
all of the extra -s when many of the strings are blank.  For example,
many of the cases only have a string variable for the 15th one (the rest
are blank) so the resulting field has a bunch of -s followed by the
contents of a(15).  I would want that to just have the contents of a(15)
alone without all of the preceding -s.  The same logic would hopefully
apply for when maybe just a(5) has information in it and the rest is
blank.

=====================
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