Hi I have this table and I want to determine when dose increases and dose decreases programatically
GROUP | DOSE | START | END |
1 | 40 | 8/24/2022 | 9/22/2022 |
1 | 70 | 9/23/2022 | 10/7/2022 |
1 | 70 | 10/9/2022 | 10/13/2022 |
1 | 64 | 10/15/2022 | 10/19/2022 |
1 | 48 | 10/21/2022 | |
2 | 35 | 8/1/2022 | 8/14/2022 |
2 | 70 | 8/15/2022 | 8/19/2022 |
2 | 80 | 8/20/2022 | 8/30/2022 |
2 | 90 | 8/31/2022 | 9/11/2022 |
2 | 90 | 9/12/2022 | 9/25/2022 |
2 | 50 | 9/26/2022 | 10/2/2022 |
2 | 35 | 10/4/2022 | 10/10/2022 |
2 | 35 | 10/11/2022 | 10/25/2022 |
2 | 20 | 10/26/2022 | 11/1/2022 |
2 | 10 | 11/2/2022 |
What I want the final product to look like is this
GROUP | DOSE | START | END | Start | End | Increase | Decrease |
1 | 40 | 8/24/2022 | 9/22/2022 | Y | |||
1 | 70 | 9/23/2022 | 10/7/2022 | Y | |||
1 | 70 | 10/9/2022 | 10/13/2022 | ||||
1 | 64 | 10/15/2022 | 10/19/2022 | Y | |||
1 | 48 | 10/21/2022 | Y | ||||
2 | 35 | 8/1/2022 | 8/14/2022 | Y | |||
2 | 70 | 8/15/2022 | 8/19/2022 | Y | |||
2 | 80 | 8/20/2022 | 8/30/2022 | Y | |||
2 | 90 | 8/31/2022 | 9/11/2022 | Y | |||
2 | 90 | 9/12/2022 | 9/25/2022 | ||||
2 | 50 | 9/26/2022 | 10/2/2022 | Y | |||
2 | 35 | 10/4/2022 | 10/10/2022 | Y | |||
2 | 35 | 10/11/2022 | 10/25/2022 | Y | |||
2 | 20 | 10/26/2022 | 11/1/2022 | Y | |||
2 | 10 | 11/2/2022 |
Y |
Any help is greatly appreciated
@Dregerator ok. Then simply take out the line setting the _end variable.
Let me know if my code works for you.
Why is End never equal to 'Y' ?
There is no end date for the last record for group 1 and group 2 . In the future, there will be a date but at the moment it is blank
@Dregerator ok. Then simply take out the line setting the _end variable.
Let me know if my code works for you.
This should get you going.
data have;
input GROUP DOSE (START END)(:mmddyy10.);
infile datalines missover;
format START END mmddyy10.;
datalines;
1 40 8/24/2022 9/22/2022
1 70 9/23/2022 10/7/2022
1 70 10/9/2022 10/13/2022
1 64 10/15/2022 10/19/2022
1 48 10/21/2022
2 35 8/1/2022 8/14/2022
2 70 8/15/2022 8/19/2022
2 80 8/20/2022 8/30/2022
2 90 8/31/2022 9/11/2022
2 90 9/12/2022 9/25/2022
2 50 9/26/2022 10/2/2022
2 35 10/4/2022 10/10/2022
2 35 10/11/2022 10/25/2022
2 20 10/26/2022 11/1/2022
2 10 11/2/2022
;
data want;
set have;
by group;
if first.group then _start = 'Y';
if last.group then _end = 'Y';
increase = ifc(dif(dose) > 0 & first.group = 0, 'Y', '');
decrease = ifc(dif(dose) < 0 & first.group = 0, 'Y', '');
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.