<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Inverse Probability weighting in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Inverse-Probability-weighting/m-p/777068#M38086</link>
    <description>&lt;P&gt;The following SAS code helped.&lt;/P&gt;
&lt;P&gt;The is is the link to the source of the SAS code&amp;nbsp;&lt;A href="http://www.baileydebarmore.com/epicode/calculating-ipw-and-smr-in-sas" target="_blank"&gt;Calculating IPW and SMR in SAS - BAILEY DEBARMORE&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***CREATING PROPENSITY SCORES********/


proc logistic data=data2 DESC;
class sex Age2  bmi2 triage_pulse2 mode_arrival pmh_copd pmh_cirrhosis
pmh_transplant pmh_cancer pmh_diabetes pmh_dialysis infection_ed_source2  Lactate1_cat
ICU_yn2 RUCA ed_dispo;
model telemed_use = sex Age2 bmi2 triage_pulse2 triage_systolic total_sofa1_ed2 
                   mode_arrival pmh_copd pmh_cirrhosis pmh_transplant pmh_cancer pmh_diabetes
                    pmh_dialysis infection_ed_source2  Lactate1_cat
				    citypop_2019 EDVolume_2019 totalbeds ICU_yn2 RUCA transferdist ed_dispo
/link=logit rsquare ;
output out=denom p=d;
run;

/****Generate numerator for stabilized weights- output a dataset with results of 
regression called num, with the resulting probabilities stored in variable n -
note that there is nothing on the right side of the equation because 
the numerator will simply be P(A=a), where a = observed exposure status; *****/
proc logistic data=data2 desc;
model telemed_use=;
output out=num p=n;
run;


/*****Generate stabilized and unstabilized weights***/
proc sort data=data2;
by record_id;run;
proc sort data=denom;
by record_id;run;
proc sort data=num;
by record_id;run;
data newdata;
mergedata2 denom num;
by record_id;
if telemed_use=1 then uw=1/d; else if telemed_use=0 then uw=1/(1-d);
if telemed_use=1 then sw=n/d; else if telemed_use=0 then sw=(1-n)/(1-d);
run;
/*Remember we can use 1 - P(exposed) for the unexposed weight components;*/
*Check the distribution of your IPTW - the mean should be 1.**/

proc means data=newdata mean sum min max;
var uw sw;
run;
/***PROPENSITY SCORE WEIGHTED OUTCOME MODEL****/
proc logistic data=newdata ; 
class telemed_use(ref='0') / param=reference ; 
model complete_adherence (event='1') = telemed_use / rsquare clodds=wald lackfit ;
weight sw ; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Oct 2021 17:19:22 GMT</pubDate>
    <dc:creator>UcheOkoro</dc:creator>
    <dc:date>2021-10-28T17:19:22Z</dc:date>
    <item>
      <title>Inverse Probability weighting</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Inverse-Probability-weighting/m-p/776620#M38040</link>
      <description>&lt;P&gt;I am working on Inverse Probability weighting. However, the codes I have are deleting the treatment group. When I remove the part of the code that does that, I have the same number of observations at the end. I am a little confused because, I was hoping it would work like matching were unmatched observations are excluded. Please, how do I achieve balance after weighting? The following are my codes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc logistic data=data2; 
model telemed_use = sex Age2 bmi2 triage_pulse2 triage_systolic total_sofa1_ed2 bmi2
                   mode_arrival pmh_copd pmh_cirrhosis pmh_transplant pmh_cancer pmh_diabetes
                    pmh_dialysis infection_ed_source2 infection_ed_source2 Lactate1_cat
				    citypop_2019 EDVolume_2019 totalbeds ICU_yn2 RUCA transferdist ed_dispo
/link=logit rsquare ;
output out = ps pred = ps; 
run;

/***inverse probability of treatment weight (IPTW)*****/
/*****the inverse of the propensity score****/
/***this code excludes the treatment grp***/
data ps_weight; 
set ps; 
ps_weight=1/ps; 
if telemed_use=_level_;
run;
/**this  code keeps full sample***/
data ps_weight; 
set ps; 
ps_weight=1/ps; 
run;

proc freq data=ps_weight;
table telemed_use;run;
/*****A SQL procedure creates a weight that reflects the sample size for each of the treatment groups***/ 
proc sql; 
create table ps_weight_adj as 
select *, (count(*)/1191)*ps_weight as ps_weight_adj 
from ps_weight 
group by telemed_use; 
quit; 

/***PROPENSITY SCORE WEIGHTED OUTCOME MODEL****/
proc logistic data=ps_weight_adj; 
class telemed_use(ref='0') / param=reference ; 
model complete_adherence (event='1') = telemed_use / rsquare clodds=wald lackfit ;
weight ps_weight_adj / normalize; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 21:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Inverse-Probability-weighting/m-p/776620#M38040</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2021-10-26T21:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Inverse Probability weighting</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Inverse-Probability-weighting/m-p/776641#M38041</link>
      <description>&lt;P&gt;Which variable(s) define "treatment group"? You have around 30 variables that we have no idea which you may consider a treatment group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is the first step where you notice the "treatment group" is missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With that many variables just how many records do you have in the Data2 data set? How many records do you have for each "treatment group"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to consider carefully reading your Model statement. It appears that you have some variables on the model statement twice: Infection_ed_source2, Bmi2. It won't hurt to only use them once and may help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly recommend that when you a magic number such as 1191 in the following that you document exactly where it came from and why it is used. Otherwise at a later time you may try to modify the code and either miss using the new value or not remember exactly how to derive it.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;proc sql; 
create table ps_weight_adj as 
select *, (count(*)/1191)*ps_weight as ps_weight_adj 
from ps_weight 
group by telemed_use; 
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 00:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Inverse-Probability-weighting/m-p/776641#M38041</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-27T00:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: Inverse Probability weighting</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Inverse-Probability-weighting/m-p/777068#M38086</link>
      <description>&lt;P&gt;The following SAS code helped.&lt;/P&gt;
&lt;P&gt;The is is the link to the source of the SAS code&amp;nbsp;&lt;A href="http://www.baileydebarmore.com/epicode/calculating-ipw-and-smr-in-sas" target="_blank"&gt;Calculating IPW and SMR in SAS - BAILEY DEBARMORE&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***CREATING PROPENSITY SCORES********/


proc logistic data=data2 DESC;
class sex Age2  bmi2 triage_pulse2 mode_arrival pmh_copd pmh_cirrhosis
pmh_transplant pmh_cancer pmh_diabetes pmh_dialysis infection_ed_source2  Lactate1_cat
ICU_yn2 RUCA ed_dispo;
model telemed_use = sex Age2 bmi2 triage_pulse2 triage_systolic total_sofa1_ed2 
                   mode_arrival pmh_copd pmh_cirrhosis pmh_transplant pmh_cancer pmh_diabetes
                    pmh_dialysis infection_ed_source2  Lactate1_cat
				    citypop_2019 EDVolume_2019 totalbeds ICU_yn2 RUCA transferdist ed_dispo
/link=logit rsquare ;
output out=denom p=d;
run;

/****Generate numerator for stabilized weights- output a dataset with results of 
regression called num, with the resulting probabilities stored in variable n -
note that there is nothing on the right side of the equation because 
the numerator will simply be P(A=a), where a = observed exposure status; *****/
proc logistic data=data2 desc;
model telemed_use=;
output out=num p=n;
run;


/*****Generate stabilized and unstabilized weights***/
proc sort data=data2;
by record_id;run;
proc sort data=denom;
by record_id;run;
proc sort data=num;
by record_id;run;
data newdata;
mergedata2 denom num;
by record_id;
if telemed_use=1 then uw=1/d; else if telemed_use=0 then uw=1/(1-d);
if telemed_use=1 then sw=n/d; else if telemed_use=0 then sw=(1-n)/(1-d);
run;
/*Remember we can use 1 - P(exposed) for the unexposed weight components;*/
*Check the distribution of your IPTW - the mean should be 1.**/

proc means data=newdata mean sum min max;
var uw sw;
run;
/***PROPENSITY SCORE WEIGHTED OUTCOME MODEL****/
proc logistic data=newdata ; 
class telemed_use(ref='0') / param=reference ; 
model complete_adherence (event='1') = telemed_use / rsquare clodds=wald lackfit ;
weight sw ; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Oct 2021 17:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Inverse-Probability-weighting/m-p/777068#M38086</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2021-10-28T17:19:22Z</dc:date>
    </item>
  </channel>
</rss>

