Deleting Characters from a String Variable

  • Follow


Hello:

I have a string variable that begins with the name of the month
followed by the date.

For example,

January 12/1/2010
March 4/3/1998
February 8/17/1990
..
..
..

What would be the simplest approach in SPSS to remove *only* the names
of the months from each cell? So, sticking with the example, I want it
to look like this:

12/1/2010
4/3/1998
8/17/1990
..
..
..

Any help would be appreciated!

Ryan

0
Reply Ryan 3/24/2010 8:34:18 PM

On Mar 24, 4:34=A0pm, Ryan <ryan.andrew.bl...@gmail.com> wrote:
> Hello:
>
> I have a string variable that begins with the name of the month
> followed by the date.
>
> For example,
>
> January 12/1/2010
> March 4/3/1998
> February 8/17/1990
> .
> .
> .
>
> What would be the simplest approach in SPSS to remove *only* the names
> of the months from each cell? So, sticking with the example, I want it
> to look like this:
>
> 12/1/2010
> 4/3/1998
> 8/17/1990
> .
> .
> .
>
> Any help would be appreciated!
>
> Ryan

Hi Ryan.  You can use CHAR.INDEX to find the position of the first
blank space in your string variable, and go from there.  E.g.,

data list list / datestr(a25).
begin data
"January 12/1/2010"
"March 4/3/1998"
"February 8/17/1990"
end data.

string newstring(a10).
* Get position of first blank space.
compute #blankpos =3D char.index(datestr," ").

* Now use it to extract a substring from the original variable .

compute newstring =3D substr(datestr,#blankpos+1).

* Date and Time Wizard: newdate.
COMPUTE newdate=3Dnumber(newstring, ADATE10).
VARIABLE LABELS newdate "".
VARIABLE LEVEL  newdate (SCALE).
FORMATS newdate (ADATE10).
VARIABLE WIDTH  newdate(10).

list.

HTH.

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."
0
Reply Bruce 3/24/2010 8:54:09 PM


On Mar 24, 4:54=A0pm, Bruce Weaver <bwea...@lakeheadu.ca> wrote:
> On Mar 24, 4:34=A0pm, Ryan <ryan.andrew.bl...@gmail.com> wrote:
>
>
>
>
>
> > Hello:
>
> > I have a string variable that begins with the name of the month
> > followed by the date.
>
> > For example,
>
> > January 12/1/2010
> > March 4/3/1998
> > February 8/17/1990
> > .
> > .
> > .
>
> > What would be the simplest approach in SPSS to remove *only* the names
> > of the months from each cell? So, sticking with the example, I want it
> > to look like this:
>
> > 12/1/2010
> > 4/3/1998
> > 8/17/1990
> > .
> > .
> > .
>
> > Any help would be appreciated!
>
> > Ryan
>
> Hi Ryan. =A0You can use CHAR.INDEX to find the position of the first
> blank space in your string variable, and go from there. =A0E.g.,
>
> data list list / datestr(a25).
> begin data
> "January 12/1/2010"
> "March 4/3/1998"
> "February 8/17/1990"
> end data.
>
> string newstring(a10).
> * Get position of first blank space.
> compute #blankpos =3D char.index(datestr," ").
>
> * Now use it to extract a substring from the original variable .
>
> compute newstring =3D substr(datestr,#blankpos+1).
>
> * Date and Time Wizard: newdate.
> COMPUTE newdate=3Dnumber(newstring, ADATE10).
> VARIABLE LABELS newdate "".
> VARIABLE LEVEL =A0newdate (SCALE).
> FORMATS newdate (ADATE10).
> VARIABLE WIDTH =A0newdate(10).
>
> list.
>
> HTH.
>
> --
> Bruce Weaver
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home
> "When all else fails, RTFM."- Hide quoted text -
>
> - Show quoted text -

Perfect! Thanks!
0
Reply Ryan 3/24/2010 9:04:32 PM

2 Replies
1777 Views

(page loaded in 0.048 seconds)

Similiar Articles:













7/20/2012 4:41:46 AM


Reply: