Fluorite | Level 6

## how to get the value digit in a lot of value numbers in sas eg

how to get the value digit in a lot of value numbers

I have a numeric variable containing a number 1991010010012346. I want to retrieve the 8 digits from 010010001 into a new numeric variable

can any one help me plz how to do this???

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: how to get the value digit in a lot of value numbers in sas eg

@merahilyana wrote:
if i have 20101401037059 nut i want 14037059.. what i must do??

1991010010012346. I want to retrieve the 8 digits from 010010001

If your variable is character you can use SUBSTR() and CATT() to concatenate the terms. If your variable is numeric you can use SUBSTRN() + CATT() to combine the values.

If you need help beyond that you'll need to explain the logic behind what's selected.

``````data have;

x1=20101401037059;
x2 = catt(substrn(x1, 5, 2),
substrn(x1, 9, 6));

y1="1991010010012346";
y2 = catt(substrn(y1, 5, 8 ));

run;

proc print; run;``````

7 REPLIES 7
Super User

## Re: how to get the value digit in a lot of value numbers in sas eg

You will sooner or later have trouble with numbers like this in SAS, as you exceed the maximum possible precision.

Do this, anyway:

``want = substr(put(number,z16.),5,8);``
Fluorite | Level 6

## Re: how to get the value digit in a lot of value numbers in sas eg

if i have 20101401037059 nut i want 14037059.. what i must do??
Super User

## Re: how to get the value digit in a lot of value numbers in sas eg

@merahilyana wrote:
if i have 20101401037059 nut i want 14037059.. what i must do??

How do you determine which substrings you need and how you concatenate them?

Super User

## Re: how to get the value digit in a lot of value numbers in sas eg

@merahilyana wrote:
if i have 20101401037059 nut i want 14037059.. what i must do??

1991010010012346. I want to retrieve the 8 digits from 010010001

If your variable is character you can use SUBSTR() and CATT() to concatenate the terms. If your variable is numeric you can use SUBSTRN() + CATT() to combine the values.

If you need help beyond that you'll need to explain the logic behind what's selected.

``````data have;

x1=20101401037059;
x2 = catt(substrn(x1, 5, 2),
substrn(x1, 9, 6));

y1="1991010010012346";
y2 = catt(substrn(y1, 5, 8 ));

run;

proc print; run;``````

Fluorite | Level 6

## Re: how to get the value digit in a lot of value numbers in sas eg

catt(substr(put(t1.IDBP,14.),5,2), substr(put(t1.IDBP,14.),9,6))

Tourmaline | Level 20

## Re: how to get the value digit in a lot of value numbers in sas eg

How do you determine what to retrieve? By position or value?

Super User

## Re: how to get the value digit in a lot of value numbers in sas eg

@merahilyana wrote:

how to get the value digit in a lot of value numbers

I have a numeric variable containing a number 1991010010012346. I want to retrieve the 8 digits from 010010001 into a new numeric variable

can any one help me plz how to do this???

What digits do you actually want? You mention 8 digits and then show 9 digits ( 010,010,001  ).

Why do you want those digits? Is it because of their value? Or their position?

Do you have that value in a number, so you have:  1,991,010,010,012,346.  If so note that SAS stores all numbers as floating point. So there is a limit on the number of digits it can store.  On a Windows/Linux machine the current largest integer than be stored exactly is: 9,007,199,254,740,992.

If you do have the value as a number and you want a particular string of digits based on where they are you can use arithmetic.  So if you wanted the 3 digits in the thousands through hundred thousands place you could use:

``want = mod( int( have/1000), 1000);``

So if you want to ignore the 4 least significant digits and keep the next 9 least significant digits you could use:

``want = mod( int( have/1e4), 1e9);``
Discussion stats
• 7 replies
• 1210 views
• 2 likes
• 5 in conversation