splitting first and last name in one field

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

splitting first and last name in one field

Raffe, Sydelle, SSA
I quite successfully created a last name from a combined name field (last, first) thanks to prior help from the list.

You'd think with a little effort, trial and error I could produce the first name. Alas, can someone provide me with the solution? Thanks.

string caselast casefrst(a25).
compute caselast = substr(casename,1,index(casename,",")-1).


Sydelle Raffe, Alameda County Social Services Agency
Information Services Division
e:mail:  [hidden email]
phone: 510-271-9174     fax: 510-271-9107
If you have a request for information, please submit an ODM request form at:  https://alamedasocialservices.org/staff/support_services/statistics_and_reports/odm/index.cfm
Reply | Threaded
Open this post in threaded view
|

Re: splitting first and last name in one field

Melissa Ives
Switch it around.

The last name instruction says to take a portion of casename beginning
with the first letter and ending with the space right before the comma.


Now you want to say take a portion of casename beginning with two after
the comma (or is it 1 after (if there is no space)?), and ending at the
end of the string, so you need to say:

*** change the 2 to a 1 if there is no space between the comma and the
first name.
Compute
casefirst=substr(casename,index(casename,",")-2,length(casename)).


Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Raffe, Sydelle, SSA
Sent: Monday, September 25, 2006 4:03 PM
To: [hidden email]
Subject: [SPSSX-L] splitting first and last name in one field

I quite successfully created a last name from a combined name field
(last, first) thanks to prior help from the list.

You'd think with a little effort, trial and error I could produce the
first name. Alas, can someone provide me with the solution? Thanks.

string caselast casefrst(a25).
compute caselast = substr(casename,1,index(casename,",")-1).


Sydelle Raffe, Alameda County Social Services Agency Information
Services Division
e:mail:  [hidden email]
phone: 510-271-9174     fax: 510-271-9107
If you have a request for information, please submit an ODM request form
at:
https://alamedasocialservices.org/staff/support_services/statistics_and_
reports/odm/index.cfm



PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.
Reply | Threaded
Open this post in threaded view
|

Upgrade 14.0.x modules --> 15.0?

Gary Rosin
In reply to this post by Raffe, Sydelle, SSA
In the promotional literature for version15, only some of the
add-on modules are listed as "updated".  If a module was
*not* updated, will upgrading to 15.0 require upgrading to
the "15.0" version of the modules that were not updated?

Gary
Reply | Threaded
Open this post in threaded view
|

Re: Upgrade 14.0.x modules --> 15.0?

Weeks, Kyle
Gary,
 
All modules need to be at the same release level as SPSS Base.
 
Regards.
 
Kyle Weeks, Ph.D.
Director of Product Management, SPSS Product Line

Product Management

SPSS Inc.

Phone: 1.312.651.3645 / Fax: 1.312.651.3690

[hidden email]

www.spss.com
SPSS Inc. helps organizations turn data into insight through predictive analytics.


________________________________

From: SPSSX(r) Discussion on behalf of Gary Rosin
Sent: Mon 9/25/2006 4:45 PM
To: [hidden email]
Subject: Upgrade 14.0.x modules --> 15.0?



In the promotional literature for version15, only some of the
add-on modules are listed as "updated".  If a module was
*not* updated, will upgrading to 15.0 require upgrading to
the "15.0" version of the modules that were not updated?

Gary
Reply | Threaded
Open this post in threaded view
|

Re: splitting first and last name in one field

Richard Ristow
In reply to this post by Raffe, Sydelle, SSA
At 05:03 PM 9/25/2006, Raffe, Sydelle, SSA wrote:

>I successfully created a last name from a combined name field (last,
>first). Alas, can someone provide me with the solution [to produce the
>first name]? Thanks.

It should be straightforward, and you'll get straightforward responses
that likely will solve it.

If they don't, could you post some test data? People format the
contents of strings all kinds of ways, some logical and others... It's
a lot more reliable to see an algorithm work on real data, than to
'prove' logically that it ought to work on what the data ought to be.

(The number of computing propositions I've proved logically that turned
out to be false...)

-Good luck,
  Richard
Reply | Threaded
Open this post in threaded view
|

Re: splitting first and last name in one field

Raffe, Sydelle, SSA
In reply to this post by Raffe, Sydelle, SSA
Richard Ristow suggestd I provide some dummy data to illustrate my problem which, he says, has a straight forward solution. So here it is. As noted before, I can separate out the last name but am having trouble extrapolating the syntax of substring to obtaining the first name. Very explicit syntax is greatly appreciated.

Rcvdget, SYbsre                                  
Pemmdtg, Adrte                                
Mkhkjhiu, Koopjoih                                    


Sydelle Raffe, Alameda County Social Services Agency
Information Services Division
e:mail:  [hidden email]
phone: 510-271-9174     fax: 510-271-9107
If you have a request for information, please submit an ODM request form at:  https://alamedasocialservices.org/staff/support_services/statistics_and_reports/odm/index.cfm
Reply | Threaded
Open this post in threaded view
|

Re: splitting first and last name in one field

Richard Ristow
At 08:34 PM 9/25/2006, Raffe, Sydelle, SSA wrote:

>Richard Ristow suggestd I provide some dummy data to illustrate my
>problem. I can separate out the last name but am having trouble
>extrapolating the syntax of substring to obtaining the first name.
>Very explicit syntax is greatly appreciated.

Sure. This should do it; this is SPSS draft output. Perhaps the most
subtle point is the DO IF; it tests for the absence of a comma.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |25-SEP-2006 23:01:17       |
|-----------------------------|---------------------------|
FullName

Rcvdget, SYbsre
Pemmdtg, Adrte
Mkhkjhiu, Koopjoih

Number of cases read:  3    Number of cases listed:  3


STRING FrstName LastName (A20).

* "#Divide" is a scratch variable (that's what beginning with   .
* '#' means), so it won't be kept in the file.                  .

COMPUTE #Divide = INDEX(FullName,',').
DO IF   #Divide EQ 0 /* No first name given */.
.  COMPUTE LastName = LTRIM(FullName).
.  COMPUTE FrstName = ''.
ELSE.
.  COMPUTE LastName = LTRIM(SUBSTR(FullName,1,#Divide-1)).
.  COMPUTE FrstName = LTRIM(SUBSTR(FullName,#Divide+1)).
END IF.
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |25-SEP-2006 23:01:17       |
|-----------------------------|---------------------------|
FullName                  FrstName             LastName

Rcvdget, SYbsre           SYbsre               Rcvdget
Pemmdtg, Adrte            Adrte                Pemmdtg
Mkhkjhiu, Koopjoih        Koopjoih             Mkhkjhiu

Number of cases read:  3    Number of cases listed:  3
Reply | Threaded
Open this post in threaded view
|

Re: splitting first and last name in one field

Barnett, Adrian (HEALTH)
Hi Sydelle,
In addition to Richard's excellent advice, I'd suggest you do a manual
check for any cases picked up by the first part of Richard's DO IF block
- namely those where there was no comma. It's possible that a comma was
omitted, or some other character substituted, assuming the data were
hand keyed. If so you'd wind up with more than you want in the LastName
variable.


To do that, I'd suggest adding the following line right at the
beginning:

Compute f = 0.

Add this just before the ELSE block:

Compute f = 1.

And then after the END IF, I'd add

Filter by f.
* Print any cases where no comma was found.
List variables = lastName


If you get any strange records printed out by this, you may need to fix
some of them  - either by hand, or, preferably, writing a bit of code
along the lines of:

Do if (ID eq 3).
-  compute LastName = 'Some surname'.
-  compute FrstName = 'some first name'.
Else if (ID eq 500).
 (etc)


(Obviously you need to substitute the appropriate name and values for
your case identifier, plus the correct values for surname and given
name). By putting the corrections in as SPSS code, you can see exactly
what you've done, and you can repeat the process (which is, regrettably,
all too often necessary). If for some reason zillions of the things turn
up, I would not use the suggested method as it would involve zillions of
ELSE IF statements. Instead I'd make up a file of corrections,
containing a case identifier (as a key variable for a TABLE match) and
the proper values of FrstName and LastName, and then use a MATCH FILES
to read them in (but storing the corrections in variables whose names
are variation on the spelling of the ones in the main file, and then
over-writing with the corrections once they have been joined on)

This may all prove to pick up no 'problem' cases, but it's prudent to
take the time to check for bad data.



Regards


Adrian

--
Adrian Barnett
Research & Information Officer                  Ph:     +61 8 82266615
Research, Analysis and Evaluation                       Fax:    +61 8
82267088
Strategic Planning and Research Branch
Strategic Planning and Population Health Division
Department of Health                   au

God is good but don't dance in a currach. - Irish proverb



This e-mail may contain confidential information, which also may be
legally privileged.  Only the intended  recipient(s) may access, use,
distribute or copy this e-mail.  If this e-mail is received in error,
please inform the sender by return e-mail and delete the original.  If
there are doubts about the validity of this message, please contact the
sender by telephone.  It is the recipient's responsibility to check the
e-mail and any attached files for viruses.




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Richard Ristow
Sent: Tuesday, 26 September 2006 12:37
To: [hidden email]
Subject: Re: splitting first and last name in one field

At 08:34 PM 9/25/2006, Raffe, Sydelle, SSA wrote:

>Richard Ristow suggestd I provide some dummy data to illustrate my
>problem. I can separate out the last name but am having trouble
>extrapolating the syntax of substring to obtaining the first name.
>Very explicit syntax is greatly appreciated.

Sure. This should do it; this is SPSS draft output. Perhaps the most
subtle point is the DO IF; it tests for the absence of a comma.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |25-SEP-2006 23:01:17       |
|-----------------------------|---------------------------|
FullName

Rcvdget, SYbsre
Pemmdtg, Adrte
Mkhkjhiu, Koopjoih

Number of cases read:  3    Number of cases listed:  3


STRING FrstName LastName (A20).

* "#Divide" is a scratch variable (that's what beginning with   .
* '#' means), so it won't be kept in the file.                  .

COMPUTE #Divide = INDEX(FullName,',').
DO IF   #Divide EQ 0 /* No first name given */.
.  COMPUTE LastName = LTRIM(FullName).
.  COMPUTE FrstName = ''.
ELSE.
.  COMPUTE LastName = LTRIM(SUBSTR(FullName,1,#Divide-1)).
.  COMPUTE FrstName = LTRIM(SUBSTR(FullName,#Divide+1)).
END IF.
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |25-SEP-2006 23:01:17       |
|-----------------------------|---------------------------|
FullName                  FrstName             LastName

Rcvdget, SYbsre           SYbsre               Rcvdget
Pemmdtg, Adrte            Adrte                Pemmdtg
Mkhkjhiu, Koopjoih        Koopjoih             Mkhkjhiu

Number of cases read:  3    Number of cases listed:  3
Reply | Threaded
Open this post in threaded view
|

Re: splitting first and last name in one field

Melissa Ives
In reply to this post by Raffe, Sydelle, SSA
The simplest is...

string caselast casefrst(a25).
compute caselast=substr(casename,1,index(casename,",")-1).
compute casefrst=substr(casename,index(casename,",")+2).
exe.


Alternatively, this works too, but the third argument is not required
and has no impact on the resulting data in this example.
compute
casefrst=substr(casename,index(casename,",")+2,length(casename)).

Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Raffe, Sydelle, SSA
Sent: Monday, September 25, 2006 7:34 PM
To: [hidden email]
Subject: Re: [SPSSX-L] splitting first and last name in one field

Richard Ristow suggestd I provide some dummy data to illustrate my
problem which, he says, has a straight forward solution. So here it is.
As noted before, I can separate out the last name but am having trouble
extrapolating the syntax of substring to obtaining the first name. Very
explicit syntax is greatly appreciated.

Rcvdget, SYbsre
Pemmdtg, Adrte
Mkhkjhiu, Koopjoih


Sydelle Raffe, Alameda County Social Services Agency Information
Services Division
e:mail:  [hidden email]
phone: 510-271-9174     fax: 510-271-9107
If you have a request for information, please submit an ODM request form
at:
https://alamedasocialservices.org/staff/support_services/statistics_and_
reports/odm/index.cfm



PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.