Pyrite | Level 9

## Match numbers within a range

 Date code rtrn exp new 2011 20 0.0098 0.0092 2012 20 0.0257 0.1235 2012 31 13.2087 0.000087 2013 31 0.00987 -0.0005479 2011 35 0.12458 -0.215 2012 35 1.205789 0.2258974 2013 87 0.1259 2014 87 -0.25874 2013 99 -0.12589 2014 99 0.0365

I have to select rtrn in new columns within a range of 70% to 140% of first exp value by code. If rtrn is within a value of 70% to 140% then we say yes otherwise no. And the I have to maintain the result by code. So, in the new column I will get either "yes" or "No/blank if it is not within the range"

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Match numbers within a range

@abdulla wrote:
Can you give me code example from the above example I used

Please indicate which records in your example data should get a "YES". Everything I examined was outside the range specified. So I am not sure that I am interpreting " rtrn within a range of 70% to 140% of first exp " the same you that you are.

This code will hold the first value of EXP across all records.

```data want;
set have;
retain holdexp;
if _n_=1 then holdexp=exp;
run;```
11 REPLIES 11
Tourmaline | Level 20

## Re: Match numbers within a range

So what does your desired result look like?

Pyrite | Level 9

## Re: Match numbers within a range

I edited my question. Please check
Diamond | Level 26

## Re: Match numbers within a range

Post test data in the form of a datastep, and post it in the code window - its the {i} above post area.

Show what the output should look like.

At a guess, I would take observation _n_=1 from the data, and merge that back onto the whole dataset, so it appears on every row, then do your calculation, then drop it.  Note New is never populated in your example, so can't see how that fits.

Pyrite | Level 9

tnx

Super User

## Re: Match numbers within a range

@abdulla wrote:
Can you give me code example from the above example I used

Please indicate which records in your example data should get a "YES". Everything I examined was outside the range specified. So I am not sure that I am interpreting " rtrn within a range of 70% to 140% of first exp " the same you that you are.

This code will hold the first value of EXP across all records.

```data want;
set have;
retain holdexp;
if _n_=1 then holdexp=exp;
run;```
Pyrite | Level 9

## Re: Match numbers within a range

" rtrn within a range of 70% to 140% of first exp " would be " rtrn within a range of 70% to 140% of every first exp by code "
Super User

## Re: Match numbers within a range

@abdulla wrote:
" rtrn within a range of 70% to 140% of first exp " would be " rtrn within a range of 70% to 140% of every first exp by code "

Show the formula you are using for 70% and 140% using some of the examples.

As I said, I used one approach and had no "Yes" values. Or ensure that you have at least one "Yes". Better would be to have a number of them.

Diamond | Level 26

## Re: Match numbers within a range

Again:

"Post test data in the form of a datastep, and post it in the code window - its the {i} above post area.

Show what the output should look like."

Nobody volunteers their time here to type in test data for you.

Pyrite | Level 9

## Re: Match numbers within a range

You don't have to mention that. If nobody understands, they will not answer. Please try to write things politely.

Diamond | Level 26

## Re: Match numbers within a range

Let me try again then.  In my post I asked you to provide some basic information which would help us to answer your question.  You have responded without providing any of the requested information, but asking me to spend my time typing in the text you provided in the original post, then spend more of my time writing code.  So to answer your question: "Can you give me code example from the above example I used", the answer I am afraid is no, I am very sorry, but I cannot.

Pyrite | Level 9

## Re: Match numbers within a range

I have found my solution by the way. Thank you for your time

Discussion stats
• 11 replies
• 1078 views
• 1 like
• 4 in conversation