Date: Thu, 24 Nov 2011 16:50:12 -0800
Reply-To: David Marso <david.marso@gmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: David Marso <david.marso@gmail.com>
Subject: Re: Syntax for creating a string variable out of the last 6
digits of another string variable
In-Reply-To: <1322136052494-5019983.post@n5.nabble.com>
Content-Type: text/plain; charset=UTF-8
string UniqueID (a6).
COMPUTE UniqueID=SUBSTR(YourStringVar,MAX(1,LENGTH(RTRIM(YourStringVar))-5
)).
--
Bruce Weaver wrote
>
> Well-spotted, Jan. Thanks. ;-)
>
>
>
> Spousta Jan wrote
>>
>> Bruce, your solution is almost correct, but does not work because of
>> blanks at the end of the strings. Better is to include the RTRIM
>> function:
>>
>> STRING UniqueID (A6).
>> COMPUTE #D1 = LENGTH(rtrim(YourStringVar)) - 5. /* position of first
>> digit .
>> IF #D1 GE 1 UniqueID = SUBSTR(YourStringVar,#D1,6).
>> EXECUTE.
>>
>> Best regards,
>>
>> Jan
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:SPSSX-L@.UGA] On Behalf Of Bruce Weaver
>> Sent: Thursday, November 24, 2011 2:59 AM
>> To: SPSSX-L@.UGA
>> Subject: Re: Syntax for creating a string variable out of the last 6
>> digits of another string variable
>>
>> Look up examples for STRING (to declare the new string variable), LENGTH
>> (to obtain the length of the original string variable), and SUBSTR (to
>> extract the last 6 digits). I don't have SPSS on this machine, but I
>> think something like this (untested) will work:
>>
>> STRING UniqueID (A6).
>> COMPUTE #D1 = LENGTH(YourStringVar) - 5. /* position of first digit .
>> IF #D1 GE 1 UniqueID = SUBSTR(YourStringVar,#D1,6).
>> EXECUTE.
>>
>> HTH.
>>
>>
>>
>> Nancy Rusinak wrote
>>>
>>> Hello - have a string variable with data of differing lengths in it.
>>> However, the last 6-digits are a unique identifier. I'd like to
>>> create a separate string variable with only those 6 digits. Anyone
>>> know some syntax for this? I'm sure it is an easy fix! Can't seem to
>>> use strung or concat functions as the data are different lengths.
>>> Example below. Many thanks!
>>> Nancy
>>>
>>> Jones, Bob~bvm312
>>> Roberts, Samuel~ccm546
>>> Smith, Ramona~bnd567
>>>
>>
>>
>> -----
>> --
>> 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/Syntax-for-creating-a-string-variable-out-of-the-last-6-digits-of-another-string-variable-tp5018788p5019029.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
>>
>>
>>
>> _____________
>> Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně
>> adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno
>> jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto
>> informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte
>> odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá
>> za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.
>>
>> Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její
>> přílohy? Myslete na přírodu.
>>
>>
>> This message and any attached files are confidential and intended solely
>> for the addressee(s). Any publication, transmission or other use of the
>> information by a person or entity other than the intended addressee is
>> prohibited. If you receive this in error please contact the sender and
>> delete the message as well as all attached documents. The sender does not
>> accept liability for any errors or omissions as a result of the
>> transmission.
>>
>> Are you sure that you really need a print version of this message and/or
>> its attachments? Think about nature.
>>
>> -.- --
>>
>> =====================
>> 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
>>
>
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Syntax-for-creating-a-string-variable-out-of-the-last-6-digits-of-another-string-variable-tp5018788p5021586.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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
|