BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Dregerator
Obsidian | Level 7

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 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

@Dregerator ok. Then simply take out the line setting the _end variable. 

 

Let me know if my code works for you.

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Why is End never equal to 'Y' ?

Dregerator
Obsidian | Level 7

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

PeterClemmensen
Tourmaline | Level 20

@Dregerator ok. Then simply take out the line setting the _end variable. 

 

Let me know if my code works for you.

PeterClemmensen
Tourmaline | Level 20

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;
Moonlight_26
Fluorite | Level 6
Woww, I have a case similar with this and I can solve my problem by using your scripting model. Thank you very much.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1208 views
  • 1 like
  • 3 in conversation