/******************************************************************/
/*Identify members who switched from drugs to another */
/******************************************************************/
data drugswitch1 (drop=lastfilled datefilled switch ds dayssupply
quantity)
drugswitch2 (keep=personid lastfilled dayssupply ds);
set drugaceiarbs;
by personid brandname;
if first.personid then switch=1; else switch=0;
if first.brandname then switch=1; else switch=0;
if switch=1
then do;
FirstFilled=input(put(datefilled,8.),yymmdd8.);
output drugswitch1;
end;
if last.personid then switch=2; else switch=0;
if last.brandname then switch=2; else switch=0;
if switch=2
then do;
LastFilled=input(put(datefilled,8.),yymmdd8.);
DS=DaysSupply;
DaysSupply=0;
output drugswitch2;
end;
run;
/******************************************************************/
/*Sort both datasets by specified variable to merge with original */
/*dataset and create new dataset */
/******************************************************************/
proc sort data=drugswitch1;
by personid;
run;
proc sort data=drugswitch2;
by personid;
run;
data drugswitch12;
merge drugswitch1 (in=a)
drugswitch2 (in=b);
by personid;
if a and b;
run;
/******************************************************************/
/*Sort the newly created dataset by specified variable to generate*/
/*frequency counts - to find out if members switched more than 1 */
/******************************************************************/
proc sort data=drugswitch12;
by personid;
run;
data freq1 (keep=personid firstfilled lastfilled ds dayssupply)
freq2 (keep=personid firstfilled lastfilled count);
set drugswitch12;
by personid;
if first.personid then Count=0;
count+1;
if last.personid;
select(count);
when (1) output freq1;
otherwise output freq2;
end;
run;
/******************************************************************/
/*Merge datasets Freq1 and Freq2 with original dataset to create */
/*new datasets separating members who did not switch and who had */
/*switched more than once from one drug to another drug */
/******************************************************************/
data acearb.drugnoswitch;
merge drugaceiarbs (in=a)
freq1 (in=b);
by personid;
if a and b;
run;
data acearb.drugwithswitch;
merge drugaceiarbs (in=a)
freq2 (in=b);
by personid;
if a and b;
run;
/******************************************************************/
/*Using dataset DrugSwitch2 identify members who switched from */
/*ACEI drug to another ACEI or ARBs to ARBs more than once and */
/*from ACEI to ARBs or ARBs to ACEI more than once */
/******************************************************************/
proc sort data=acearb.drugonescript out=drugonescript;
by personid;
run;
data switch2
switch3
switch4
switch5;
set acearb.drugwithswitch;
select(count);
when (2) output switch2;
when (3) output switch3;
when (4) output switch4;
otherwise output switch5;
end;
run;
%let x1=switch2;
%let x2=switch3;
%let x3=switch4;
%let x4=switch5;
%let x5=drugonescript;
%macro sort;
%do i=1 %to 5;
proc sort data=&&x&i nodupkey;
by personid gender;
run;
proc means data=&&x&i noprint;
by personid;
id gender;
var bene;
output out=&&x&i..d
sum=&&x&i..f;
run;
%end;
%mend;
%sort;
data switchfreq;
merge switch2d
switch3d
switch4d
switch5d
drugonescriptd;
by personid;
if switch2f<1 then switch2f=0;
if switch3f<1 then switch3f=0;
if switch4f<1 then switch4f=0;
if switch5f<1 then switch5f=0;
if drugonescriptf<1 then drugonescriptf=0;
run;
ods html body='c:\DrugSwitchers.html'
style=minimal
rs=none;
proc report data=switchfreq headline spacing=2 missing split='*' nowd;
column gender drugonescriptf switch2f switch3f switch4f switch5f total;
define gender/group width=7 format=$fmtsex. 'Gender';
define drugonescriptf/sum width=9 format=comma9. 'One Script*Only';
define switch2f/sum width=9 format=comma9. 'Switched*Drugs*1x';
define switch3f/sum width=9 format=comma9. 'Switched*Drugs*2x';
define switch4f/sum width=9 format=comma9. 'Switched*Drugs*3x';
define switch5f/sum width=9 format=comma9. 'Switched*More than*4x';
define total/computed width=9 format=comma9. 'Total';
compute total;
total=drugonescriptf.sum+switch2f.sum+switch3f.sum+switch4f.sum+switch5f.sum;
endcomp;
break after gender/skip suppress;
rbreak after/dol dul skip summarize;
run;
ods html close;
BackToTop BackToDocument HomePage
|