@Astounding Following up on this.
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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.