BookmarkSubscribeRSS Feed
tuckjosh
Fluorite | Level 6

@Astounding Following up on this.

J. E. Tucker, MPH (he.him.his)
Astounding
PROC Star

For many drugs, you need many variables to track the switches.  Borrowing from @mkeintz :

 

proc sort data=have;
  by state edate;
run;

data want (keep=state flip:);
  set have;
  by state;

  array drug    matbupie      metmeth      matnal;
  array flips1 {3}  flip_to_1_matbupie flip_to_1_matmeth flip_to_1_matnal;
  array flips0 {3}  flip_to_0_matbupie flip_to_0_matmeth flip_to_0_matnal;
  if first.state then do _n_=1 to 3;
    flips1{_n_}=0;
    flips0{_n_}=0;
  end;

  do _n_=1 to 3;
    flipval = dif(drug);
    if first.state=0 then do;
       if flipval=1 then flips1{_n_} + 1;
       else if flipval=-1 then flips0{_n_} + 1;
    end;
  end;

  if last.state;
run;

This gives you all the pieces you might need to do your calculations, with one possible exception.  The logic would need to change if there is a flip on multiple drugs at the same time.  This logic counts each flip.  If two drugs flip, both are counted.  As long as that is your intention, this would count properly.  However, if two drugs flip to 1 at the same time, and you would like to count that only once, changes are needed.

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 16 replies
  • 1750 views
  • 4 likes
  • 6 in conversation