Hi-
How do I use INDEX or some other command to test a text variable for a specific character at a specific location? I need first position in this case. I'm trying to clean search results such that : (something) = something and something (else) = something (else) syntax following this message would return 'omething (else)' without controlling INDEX to examine first characters only. Thanks for any suggestions. Regards, Brian IF (INDEX(newstring1,'(')=0) AllSearchTErms = UPCASE(newstring1) . EXECUTE . IF (INDEX(newstring1,'(')>0) AllSearchTErms = UPCASE(SUBST(newstring1,2)) . EXECUTE . |
Brian:
I'm not sure of the exact string manipulation you are trying to do, but this point might get you started: Since INDEX returns a number (the position within the string), it can be used as an argument in SUBSTR. INDEX can be used to find the number for the start and/or end point for SUBSTR. You use the results of INDEX in arithmetic operations. For example: this bit of code will create a variable starting from the first position after the open parenthesis: ** test data**-- use your data instead. DATA LIST FREE (",") /textvar (a20). BEGIN DATA (something) something (else) nothing END DATA. ** update to your variable names. STR newstring (a20). IF index(textvar,'(' ) GT 0 newstring = UPCASE(SUBSTR( textvar,INDEX(textvar,'(' )+1 )). EXECUTE. "INDEX(testvar,'(' ) +1 " marks the start position inside the brackets. If you have specifics about the manipulation, we can probably code to get the result. HTH --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Brian Moore Sent: Tuesday, September 05, 2006 11:29 AM To: [hidden email] Subject: INDEX specified character location Hi- How do I use INDEX or some other command to test a text variable for a specific character at a specific location? I need first position in this case. I'm trying to clean search results such that : (something) = something and something (else) = something (else) syntax following this message would return 'omething (else)' without controlling INDEX to examine first characters only. Thanks for any suggestions. Regards, Brian IF (INDEX(newstring1,'(')=0) AllSearchTErms = UPCASE(newstring1) . EXECUTE . IF (INDEX(newstring1,'(')>0) AllSearchTErms = UPCASE(SUBST(newstring1,2)) . EXECUTE . |
In reply to this post by Brian Moore-3
At 12:29 PM 9/5/2006, Brian Moore wrote:
>How do I use INDEX or some other command to test a text variable for a >specific character at a specific location? I need first position in >this case. Well, from what follows I'm not sure this what you really want, but what you say you want is very simple: To test for 'A' in position 1 of string TEST_IT, IF (SUBSTR(TEST_IT,1,1) EQ 'A')... To test for 'X' in position 17, IF (SUBSTR(TEST_IT,17,1) EQ 'X')... >I'm trying to clean search results such that : > >(something) = something > >and > >something (else) = something (else) That looks like you're trying to remove parentheses from the string before comparing. I'm happy to give syntax for that, but I'd like to be clearer what you want, first. >syntax following this message would return 'omething (else)' without >controlling INDEX to examine first characters only. 'Fraid I don't get this one. Can you give the code you have in full, what it produces, and what you want it to produce? Good luck, Richard Ristow |
Free forum by Nabble | Edit this page |