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

Hi, 

 

I am trying to create reduce variable from below data, reduce value starts from 0 and increases if any reduction in dose and retains tilll next reduction.

 

I have data like below

 

anyalamadugu_0-1632238026857.png

 

Can anyone provide the logic for this.

 

Thanks,

Adi

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

data want;
    set have;
    by id;
    if first.id then reduce=0;
    reduce+(dif(dose)<0 and not first.id);
run;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

data want;
    set have;
    by id;
    if first.id then reduce=0;
    reduce+(dif(dose)<0 and not first.id);
run;
--
Paige Miller
chinna0369
Pyrite | Level 9

Somehow this is not working with my data, is there any other way?

PaigeMiller
Diamond | Level 26

Providing data as a screen capture isn't helpful, as we can't run code against a screen capture. The proper way to provide data is in a SAS data step, instructions are here: https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

 

Saying "it doesn't work" doesn't help either. We need details, we need your data, we need to see your code. What about it doesn't work? Is there an error in the log? We will need to see your log in order to diagnose errors in the log. Or if the output wrong, if so please show us and explain.

--
Paige Miller
PaigeMiller
Diamond | Level 26

Also, please don't post the same question more than once.

 

From this point forward, all discussion of this question should be in your other thread at https://communities.sas.com/t5/SAS-Programming/Assign-sequence-based-dose-starting-from-zero/m-p/768...

 

I will not discuss this topic further in this thread, all comments should go to the other thread.

--
Paige Miller
Kurt_Bremser
Super User

 


@chinna0369 wrote:

Somehow this is not working with my data, is there any other way?


Provide example data in usable form. Post your data as a data step with datalines, as I showed you here.

 

We cannot code and test against pictures, we need usable data. DO NOT SKIP THE ABOVE.

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
  • 5 replies
  • 714 views
  • 0 likes
  • 3 in conversation