From: Ruslan Kirhizau on
Hi Dimitri,
This should work:
y =left( put(x,10.));

Ruslan
------Original Message------
From: Dimitri Shvorob
Sender: SAS(r) Discussion
To: SAS-L(a)LISTSERV.UGA.EDU
ReplyTo: Dimitri Shvorob
Subject: SUBSTR Madness
Sent: Sep 27, 2009 9:39 AM

I am trying to extract first 6 digits of a (variable-length) numeric ID.

data test;
x = 614245034;
y = put(x,10.);
z = substr(y,1,6);
w = input(z,6.0);
run;
proc print; run;

Obs x y z w

1 614245034 614245034 61424 61424

Arrgh..

Can anyone help?

Thank you.


Sent on the Now Network� from my Sprint® BlackBerry
From: Mike Rhoads on
Or you could use the -L format modifier to left-justify the result:

y = put(x,10.-L);


Mike Rhoads
RhoadsM1(a)Westat.com


-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Ruslan Kirhizau
Sent: Sunday, September 27, 2009 9:52 AM
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: Re: SUBSTR Madness

Hi Dimitri,
This should work:
y =left( put(x,10.));

Ruslan
------Original Message------
From: Dimitri Shvorob
Sender: SAS(r) Discussion
To: SAS-L(a)LISTSERV.UGA.EDU
ReplyTo: Dimitri Shvorob
Subject: SUBSTR Madness
Sent: Sep 27, 2009 9:39 AM

I am trying to extract first 6 digits of a (variable-length) numeric ID.

data test;
x = 614245034;
y = put(x,10.);
z = substr(y,1,6);
w = input(z,6.0);
run;
proc print; run;

Obs x y z w

1 614245034 614245034 61424 61424

Arrgh..

Can anyone help?

Thank you.


Sent on the Now Network� from my Sprint® BlackBerry
From: Joe Matise on
LOG10 method is also fun:

data test;
input x;
datalines;
1234567890
123456789
12345678
1234567
123456
12345
;;;;
run;

data want;
set test;
put _y= _z=;
y = floor(x/10**(floor(log10(x))-5));
put x= y=;
run;

You can define Y as char or numeric in this model, as you prefer.
-Joe

On Sun, Sep 27, 2009 at 8:39 AM, Dimitri Shvorob <
dimitri.shvorob(a)vanderbilt.edu> wrote:

> I am trying to extract first 6 digits of a (variable-length) numeric ID.
>
> data test;
> x = 614245034;
> y = put(x,10.);
> z = substr(y,1,6);
> w = input(z,6.0);
> run;
> proc print; run;
>
> Obs x y z w
>
> 1 614245034 614245034 61424 61424
>
> Arrgh..
>
> Can anyone help?
>
> Thank you.
>
From: Paul Dorfman on
Dmitri,
Other gentlesasmen having already pointed out the need to left-justify, my =
take on it is that since your input is a numric and you need the result as =
a number as well, you can avoid the double type conversion altogether:
data _null_ ; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0 input x ; =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0=A0=A0=A0 w =3D int(x/10**((floor(log10(x))-5)*(x=3D>1e5))) ;=A0=A0 =
put x=3D16. @18 w=3D16. ; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0=A0cards ; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
12345678912345 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A010293847 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0=A09753 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0100000 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0=A029384756273 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0; =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0run ; =A0 =A0 =A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0---------------------------------------x=3D1=
2345678912345 y=3D123456x=3D10293847 =A0 =A0 =A0 y=3D102938x=3D9753 =A0 =A0=
=A0 =A0 =A0 y=3D0x=3D100000 =A0 =A0 =A0 =A0 y=3D100000x=3D29384756273 =A0 =
=A0y=3D293847=A0=A0 =A0Kind regards------------Paul DorfmanJax, FL---------=
--- =A0=A0
--- On Sun, 9/27/09, Dimitri Shvorob <dimitri.shvorob(a)VANDERBILT.EDU> wrote=
:

From: Dimitri Shvorob <dimitri.shvorob(a)VANDERBILT.EDU>
Subject: SUBSTR Madness
To: SAS-L(a)LISTSERV.UGA.EDU
Date: Sunday, September 27, 2009, 9:39 AM

I am trying to extract first 6 digits of a (variable-length) numeric ID.

data test;
=A0 x =3D 614245034;
=A0 y =3D put(x,10.);
=A0 z =3D substr(y,1,6);
=A0 w =3D input(z,6.0);
=A0 run;
proc print; run;

Obs=A0 =A0 =A0 =A0 x=A0 =A0 =A0 =A0 =A0 =A0 y=A0 =A0 =A0 =A0 =A0 z=A0 =A0 =
=A0 =A0 w

1=A0 =A0=A0=A0614245034=A0 =A0 614245034=A0 =A0 61424=A0 =A0 61424

Arrgh..

Can anyone help?

Thank you.
From: Mike Zdeb on
hi ...using Joe's data ...


data test;
input x @@;
datalines;
1234567890 123456789 12345678 1234567 123456
;
run;

data test;
set test;
y=input(cat(x),6.);
run;

run;

proc print data=test noobs;
run;


x y
1234567890 123456
123456789 123456
12345678 123456
1234567 123456
123456 123456




--
Mike Zdeb
U(a)Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

> I am trying to extract first 6 digits of a (variable-length) numeric ID.
>
> data test;
> x = 614245034;
> y = put(x,10.);
> z = substr(y,1,6);
> w = input(z,6.0);
> run;
> proc print; run;
>
> Obs x y z w
>
> 1 614245034 614245034 61424 61424
>
> Arrgh..
>
> Can anyone help?
>
> Thank you.
>