LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 6 Oct 2005 01:17:28 -0700
Reply-To:     Cady Wan <xqw1@yahoo.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Cady Wan <xqw1@yahoo.com>
Subject:      Re: Extracting information from post codes.
In-Reply-To:  <5.1.0.14.2.20051005175458.0323ec10@pop.mindspring.com>
Content-Type: text/plain; charset=iso-8859-1

This also can be done by:

*##########################################. data list list /current (a8). begin data DG10 8SR M694JD BT3 1DR end data. *##########################################.

loop #i = length(current) to 1 by -1. - if index('0123456789',substr(current,#i,1))>0 firstdigit = #i. end loop. string required(a4). do if (firstdigit > 1). compute required = substr(current, 1, firstdigit-1). end if. if (sysmis(firstdigit)) required = current. *#############################################.

Regards, Cady

--- Richard Ristow <wrristow@mindspring.com> wrote:

> At 01:34 PM 10/5/2005, David Lindsay wrote: > > >I have a number of GB post codes. [...] I guess > that I need to detect > >the first [digit] and then extract the letters to > the left." > > Art's posted a fine solution. Here's an alternative, > which I'm posting > mainly to illustrate a 'cute' use of INDEX: Finding > the first > occurrence of any character on a list. (Alas, > there's no way to find > the first occurrence of any character NOT on a > list.) > > If there's any practical advantage, it's that this > code will pick off a > string of any length preceding the first digit. > Note, also, that '#IDX' > is a scratch variable, so will not be present in > (possibly, clutter) > the output file. (On the other hand, if it were a > normal variable, it > would be easier to diagnose bugs.) > > * ............................ > LIST. > Notes > |---------------------------|-----------------------| > |Output Created |05 Oct 05 17:52:27 > | > |---------------------------|-----------------------| > CURRENT REQUIRED > > DG10 8SR DG > M694JD M > BT3 1DR BT > > Number of cases read: 3 Number of cases listed: > 3 > > > STRING COMPUTED (A4). > COMPUTE #IDX = INDEX(CURRENT,'0123456789',1). > COMPUTE COMPUTED = SUBSTR(CURRENT,1,#IDX-1). > > LIST. > Notes > |---------------------------|-----------------------| > |Output Created |05 Oct 05 17:52:27 > | > |---------------------------|-----------------------| > CURRENT REQUIRED COMPUTED > > DG10 8SR DG DG > M694JD M M > BT3 1DR BT BT > > Number of cases read: 3 Number of cases listed: > 3 >

__________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com


Back to: Top of message | Previous page | Main SPSSX-L page