BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
merahilyana
Fluorite | Level 6

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
Reeza
Super User

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

 

1991010010012346. I want to retrieve the 8 digits from 010010001


Your patterns don't match. 

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;

 

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

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);
merahilyana
Fluorite | Level 6
if i have 20101401037059 nut i want 14037059.. what i must do??
Reeza
Super User

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

 

1991010010012346. I want to retrieve the 8 digits from 010010001


Your patterns don't match. 

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;

 

merahilyana
Fluorite | Level 6

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

PeterClemmensen
Tourmaline | Level 20

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

Tom
Super User Tom
Super User

@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);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1374 views
  • 2 likes
  • 5 in conversation