Re: frist ? character of value

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: frist ? character of value

Barnett, Adrian (HEALTH)-2
On Fri, 2 Mar 2007 18:02:36 +0000, behnaz shirazi <[hidden email]> wrote:

>Hello Dear All,
>
>I wonder if you know how I can get the 2 or 3 first character of a value.for
>example I have XX variable with following value:
>
>1|01/02/2005
>1|02/03/2005
>14|04/08/2006
>..
>..
>I want to create a new variable from this variable which contains just frist
>2 or 3 character of this values:
>1
>1
>14

Hi Behnaz
If your data always have the vertical bar character immediately preceding
the date portion of the variable, and what you want is everything to the
left of that, you can combine the substr() function with the index()
function to pick off those characters like this (untested) code:

string firstbit(a3).
compute firstbit = substr(XX,1,index(XX,'|')-1).

The declaration of firstbit as 3 characters assumes that it can indeed be up
to 3 characters wide as you first indicated.

Regards
Adrian Barnett