|
Hi-
I have a variable that currently have data (as a string) looking like this: G1-05024-003-024 However, I want to remove the "G1" and the dashes from it, into a new variable so that it looks like this: 05024003024 Can someone show me an easy way of doing this? Thanks, Jenny ===================== 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 |
|
Hi Jennifer,
You can try the following syntax, data list list / Var_dash(a16). begin data. G1-05024-003-024 G4-06034-006-025 G3-05024-003-026 end data. list. string New_Var (a16). compute New_Var = concat(substr(Var_dash, 4, 5), substr(Var_dash, 10, 3), substr(Var_dash, 14, 3)). Exe. Cheers! Mahbub -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jennifer Steffes Sent: Tuesday, November 20, 2007 2:51 PM To: [hidden email] Subject: removing dashes from variable Hi- I have a variable that currently have data (as a string) looking like this: G1-05024-003-024 However, I want to remove the "G1" and the dashes from it, into a new variable so that it looks like this: 05024003024 Can someone show me an easy way of doing this? Thanks, Jenny ===================== 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 ______________________________________________________________________ This email has been scanned by the CAMH Email Security System. ______________________________________________________________________ ______________________________________________________________________ This email has been scanned by the CAMH Email Security System. ______________________________________________________________________ ===================== 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 Jennifer Steffes
I'm not sure whether the new variable should remain a string or a number so
this will create both of them: * create a new var so we don't lose the old. STRING newstringvar(a11). * strip off the 1st segment with substring and replace the blanks. COMPUTE newstringvar=REPLACE(SUBSTRING(stringvar,4),'-',''). * create a number from newstringvar with an N format. COMPUTE newnumbervar=NUMBER(newstringvar,f11). FORMATS newnumbervar(n11.0). -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jennifer Steffes Sent: Tuesday, November 20, 2007 12:51 PM To: [hidden email] Subject: removing dashes from variable Hi- I have a variable that currently have data (as a string) looking like this: G1-05024-003-024 However, I want to remove the "G1" and the dashes from it, into a new variable so that it looks like this: 05024003024 Can someone show me an easy way of doing this? Thanks, Jenny ===================== 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 ===================== 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 Jennifer Steffes
Hi ViAnn,
You solution seems to be okay, but what I don't understand is why you don't define newnumbervar as an N variable (now you give it an N display/print format), as in NUMERIC newnumbervar (N11.0). COMPUTE newnumbervar=NUMBER(newstringvar,n11.0). Cheers!! Albert-Jan -----Oorspronkelijk bericht----- Van: SPSSX(r) Discussion [mailto:[hidden email]] Namens ViAnn Beadle Verzonden: woensdag 21 november 2007 2:33 Aan: [hidden email] Onderwerp: Re: removing dashes from variable I'm not sure whether the new variable should remain a string or a number so this will create both of them: * create a new var so we don't lose the old. STRING newstringvar(a11). * strip off the 1st segment with substring and replace the blanks. COMPUTE newstringvar=REPLACE(SUBSTRING(stringvar,4),'-',''). * create a number from newstringvar with an N format. COMPUTE newnumbervar=NUMBER(newstringvar,f11). FORMATS newnumbervar(n11.0). -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jennifer Steffes Sent: Tuesday, November 20, 2007 12:51 PM To: [hidden email] Subject: removing dashes from variable Hi- I have a variable that currently have data (as a string) looking like this: G1-05024-003-024 However, I want to remove the "G1" and the dashes from it, into a new variable so that it looks like this: 05024003024 Can someone show me an easy way of doing this? Thanks, Jenny ===================== 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 ===================== 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 --------------- Aan de inhoud van dit e-mailbericht kunnen geen rechten worden ontleend. De informatie verzonden in dit e-mailbericht is uitsluitend bestemd voor de geadresseerde. Het Centraal Bureau voor de Statistiek staat niet in voor de juiste en volledige overbrenging van de inhoud van een verzonden e-mailbericht noch voor tijdige ontvangst daarvan. No rights may be derived from the contents of this e-mail message. The information in this e-mail message is intended only for the addressee. Statistics Netherlands cannot vouch for the correctness and completeness of the contents of e-mail messages, nor for the timely receipt thereof. ====================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 |
|
That work as well. Same number of commands.
-----Original Message----- From: Roskam, Drs. A.R. [mailto:[hidden email]] Sent: Wednesday, November 21, 2007 1:33 AM To: ViAnn Beadle; [hidden email] Subject: RE: Re: removing dashes from variable Hi ViAnn, You solution seems to be okay, but what I don't understand is why you don't define newnumbervar as an N variable (now you give it an N display/print format), as in NUMERIC newnumbervar (N11.0). COMPUTE newnumbervar=NUMBER(newstringvar,n11.0). Cheers!! Albert-Jan -----Oorspronkelijk bericht----- Van: SPSSX(r) Discussion [mailto:[hidden email]] Namens ViAnn Beadle Verzonden: woensdag 21 november 2007 2:33 Aan: [hidden email] Onderwerp: Re: removing dashes from variable I'm not sure whether the new variable should remain a string or a number so this will create both of them: * create a new var so we don't lose the old. STRING newstringvar(a11). * strip off the 1st segment with substring and replace the blanks. COMPUTE newstringvar=REPLACE(SUBSTRING(stringvar,4),'-',''). * create a number from newstringvar with an N format. COMPUTE newnumbervar=NUMBER(newstringvar,f11). FORMATS newnumbervar(n11.0). -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jennifer Steffes Sent: Tuesday, November 20, 2007 12:51 PM To: [hidden email] Subject: removing dashes from variable Hi- I have a variable that currently have data (as a string) looking like this: G1-05024-003-024 However, I want to remove the "G1" and the dashes from it, into a new variable so that it looks like this: 05024003024 Can someone show me an easy way of doing this? Thanks, Jenny ===================== 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 ===================== 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 --------------- Aan de inhoud van dit e-mailbericht kunnen geen rechten worden ontleend. De informatie verzonden in dit e-mailbericht is uitsluitend bestemd voor de geadresseerde. Het Centraal Bureau voor de Statistiek staat niet in voor de juiste en volledige overbrenging van de inhoud van een verzonden e-mailbericht noch voor tijdige ontvangst daarvan. No rights may be derived from the contents of this e-mail message. The information in this e-mail message is intended only for the addressee. Statistics Netherlands cannot vouch for the correctness and completeness of the contents of e-mail messages, nor for the timely receipt thereof. ===================== 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 |
| Free forum by Nabble | Edit this page |
