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: 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!

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
  • 1594 views
  • 4 likes
  • 6 in conversation