- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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???
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
catt(substr(put(t1.IDBP,14.),5,2), substr(put(t1.IDBP,14.),9,6))
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How do you determine what to retrieve? By position or value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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);