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"
@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;
So what does your desired result look like?
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.
tnx
@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;
@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.
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.
You don't have to mention that. If nobody understands, they will not answer. Please try to write things politely.
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.
I have found my solution by the way. Thank you for your time
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.