BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abdulla
Pyrite | Level 9
Datecodertrnexpnew
2011200.00980.0092 
2012200.02570.1235 
20123113.20870.000087 
2013310.00987-0.0005479 
2011350.12458-0.215 
2012351.2057890.2258974 
2013870.1259  
201487-0.25874  
201399-0.12589  
2014990.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
ballardw
Super User

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

View solution in original post

11 REPLIES 11
PeterClemmensen
Tourmaline | Level 20

So what does your desired result look like?

abdulla
Pyrite | Level 9
I edited my question. Please check
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

abdulla
Pyrite | Level 9

tnx

ballardw
Super User

@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
Pyrite | Level 9
" 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 "
ballardw
Super User

@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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

abdulla
Pyrite | Level 9

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

abdulla
Pyrite | Level 9

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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