Hi all, I have string data of numbers as below Codes So if I need last character as 2 How to get., I am using functions but didn't get it. Suggestions please. |
Administrator
|
Look up RTRIM and SUBSTR in the FM!
--
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Rajeshms
If your original variable is called "v1", try
string last(a1). compute last = char.substr(v1,length(rtrim(v1))). exe. The tricky part is that the length of a string value always equals the length of the string variable since string values are right padded with spaces. This is counteracted by right trimming (rtrim) off these spaces before taking the length. Kind regards, Ruben Geert van den Berg |
Administrator
|
In reply to this post by David Marso
And perhaps LENGTH too? (Or the new-fangled versions of those functions, CHAR.SUBSTR and CHAR.LENGTH.)
In the FM, go to Universals > Transformation Expressions > String Functions.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by Ruben Geert van den Berg
In Unicode mode, the string values are
automatically rtrimmed.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Ruben Geert van den Berg <[hidden email]> To: [hidden email], Date: 11/13/2013 06:38 AM Subject: Re: [SPSSX-L] String data splitting Sent by: "SPSSX(r) Discussion" <[hidden email]> If your original variable is called "v1", try string last(a1). compute last = char.substr(v1,length(rtrim(v1))). exe. The tricky part is that the length of a string value always equals the length of the string variable since string values are right padded with spaces. This is counteracted by right trimming (rtrim) off these spaces before taking the length. Kind regards, Ruben Geert van den Berg -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/String-data-splitting-tp5723026p5723030.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
In reply to this post by Rajeshms
The following so work if you have not found a better solution. DATA LIST /CODES 1-3 (A) . BEGIN DATA 012 13 Q12 1.67
Sd7 END DATA. LIST. COMPUTE LAST_DIGIT=NUMBER(CHAR.SUBSTR(RTRIM(CODES), LENGTH(RTRIM(CODES))),F1). VARIABLE LABELS LAST_DIGIT 'Last Digit'. EXECUTE.
FORMATS LAST_DIGIT (F1). The RTRIM command is to remove leading blanks, the CHAR.SUBSTR is to extract the substring starting from position defined by Length to the end, while the NUMBER command is to convert the extracted substring into a number.
best wishes Forcheh On Wed, Nov 13, 2013 at 3:23 PM, Rajeshms <[hidden email]> wrote:
Professor Ntonghanwah Forcheh Department of Statistics, University of Botswana Private Bag UB00705, Gaborone, Botswana. Office: +267 355 2696, Mobile: Orange +267 75 26 2963, Bmobile: 73181378: Mascom 754 21238 fax: +267 3185099; Alternative Email: [hidden email] *@Honesty is a Virtue, Freedom of the Mind is Power. Motto: Never be afraid to be honest, Never lie to yourself, Trust in the Truth and you will be forever free.* |
Free forum by Nabble | Edit this page |