BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
withyin
Fluorite | Level 6

In "Example 98.1 Propensity Score Weighting", how did SAS calculate the weighted means 0.2454 and 0.2381 in Table "Output 98.1.2: Propensity Score Information"?  Or all the weighted means in Table "Output 98.1.3: Variable Information"? 

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_psmatch_examples01.htm&docsetVers...

 

I got the weights 460.45 and 489.59 as the sums of _ATEWgt_ for Drug_X and Drug_A respectively in both tables. But multiplying _ATEWgt_ with age, BMI, or _ps_ could not give me the same weighted means in those tables. 

 

I was trying to use the _ATEWgt_ (in a survival analysis) as the weight for PROC PHREG. Because of the uncertainty I felt from the experience above, I am not sure whether I can use _ATEWgt_ as the weight in PROC PHREG.

 

Thank you for your help!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I didn't end up using your code, not sure what it all does. However, my checks does show that the results do match. 

I checked the weighted mean of AGE and BMI and they matched exactly. 

 

ods graphics off;
ods select psinfo varinfo;
proc psmatch data=drugs region=allobs;
   class Drug Gender;
   psmodel Drug(Treated='Drug_X')= Gender Age BMI;
   psweight weight=atewgt nlargestwgt=6;
   assess lps var=(Gender Age BMI)
          / varinfo;
   id BMI;
   output out(obs=all)=OutEx1 weight=_ATEWgt_;
run;


proc sort data=outex1;
by drug;
run;

proc means data=outex1 N MEAN SUM;
    by drug;
    var age bmi ; 
    weight _atewgt_ ;
    output out=mean 
    mean= sum= / autoname;
run;

Results:

 

The PSMATCH Procedure

 
Variable Information
Variable Observations Treated (Drug = Drug_X) Control (Drug = Drug_A) Treated -
Control
N Weight Mean Standard
Deviation
Minimum Maximum N Weight Mean Standard
Deviation
Minimum Maximum Mean
Difference
Logit Prop Score All 113   -0.88062 0.681761 -2.74745 0.58035 373   -1.52059 0.844486 -3.88386 0.78036 0.63997
  Region 113   -0.88062 0.681761 -2.74745 0.58035 373   -1.52059 0.844486 -3.88386 0.78036 0.63997
  Weighted 113 460.45 -1.25406 0.741386 -2.74745 0.58035 373 489.59 -1.35103 0.894234 -3.88386 0.78036 0.09698
Age All 113   36.30973 5.534114 26.00000 49.00000 373   40.40483 6.579103 25.00000 57.00000 -4.09509
  Region 113   36.30973 5.534114 26.00000 49.00000 373   40.40483 6.579103 25.00000 57.00000 -4.09509
  Weighted 113 460.45 38.59813 5.773228 26.00000 49.00000 373 489.59 39.32670 6.771606 25.00000 57.00000 -0.72857
BMI All 113   24.49257 1.863797 20.33000 28.34000 373   23.75327 1.980778 19.22000 28.61000 0.73930
  Region 113   24.49257 1.863797 20.33000 28.34000 373   23.75327 1.980778 19.22000 28.61000 0.73930
  Weighted 113 460.45 24.03522 1.896607 20.33000 28.34000 373 489.59 23.95492 2.004019 19.22000 28.61000 0.08030
Gender All 113   0.43363 0.495575     373   0.45845 0.498270     -0.02482
  Region 113   0.43363 0.495575     373   0.45845 0.498270     -0.02482
  Weighted 113 460.45 0.47335 0.499289     373 489.59 0.45479 0.497952     0.01856

The MEANS Procedure

 
Variable N Mean Sum
Age
BMI
373
373
39.3266975
23.9549166
19253.88
11728.04
 
Variable N Mean Sum
Age
BMI
113
113
38.5981316
24.0352189
17772.51
11067.02

 

Honestly, I don't know what that first table is reporting, at least without some more research but it seems to me the weights are accurately reported.

View solution in original post

9 REPLIES 9
withyin
Fluorite | Level 6

I calculated "means" for age, bmi, _ps_ and the "weighted means" based on the products  _ATEWgt_ *(age, bmi, and _ps_) using PROC MEANS. 

 

All the "means" match the means in the tables but none of my "weighted means", even though the sums of _ATEWgt_ match the ones in the tables for each drug. 

 

Apparently, _ATEWgt_ was not supposed to be used as the multiplier to get the weighted means. Then, how to get the weighted means? 

 

Thanks!

Reeza
Super User

Can you post the code you used to find your weighted means?

To be clear you're using exactly the data in the example, not your customized data, just trying to recreate the results from the documentation?

 


@withyin wrote:

I calculated "means" for age, bmi, _ps_ and the "weighted means" based on the products  _ATEWgt_ *(age, bmi, and _ps_) using PROC MEANS. 

 

All the "means" match the means in the tables but none of my "weighted means", even though the sums of _ATEWgt_ match the ones in the tables for each drug. 

 

Apparently, _ATEWgt_ was not supposed to be used as the multiplier to get the weighted means. Then, how to get the weighted means? 

 

Thanks!


 

withyin
Fluorite | Level 6

Thank you Reeza for your help.

Here are my codes: 

 

proc psmatch data=drugs region=allobs;
   class Drug Gender;
   psmodel Drug(Treated='Drug_X')= Gender Age BMI;
   psweight weight=atewgt nlargestwgt=6;
   assess lps var=(Gender Age BMI)
          / varinfo plots=(barchart boxplot(display=(lps BMI)) wgtcloud);
   id BMI;
   output out(obs=all)=OutEx1 weight=_ATEWgt_;
run;

data weight;
	set OutEx1;
	age_wt=age*_ATEWgt_;
	bmi_wt=bmi*_ATEWgt_;
	ps_wt=_ps_*_ATEWgt_;
run;
proc sort;
  by drug;
proc means noprint;
  	by drug;
  	var age age_wt bmi bmi_wt _ps_ ps_wt _atewgt_;
  	output out=mean 
	mean=agem age_wtm bmim bmi_wtm _ps_m ps_wtm _atewgtm
	sum=ages age_wts bmis bmi_wts _ps_s ps_wts _atewgts;
run;
proc print;run;

The PROC PSMATCH part (and parts prior that) was copied from Example 98.1. 

None of the weighted means (*_wtm) match that in the tables 98.1.2 and 98.1.3, even though _atewgts match the weights in Tables 98.1.2 and 98.1.3. 

 

Thanks!

Reeza
Super User
I won't have time to look at this until tonight, so hopefully someone else does, but if I don't remember ping me.
withyin
Fluorite | Level 6
Thanks! Please take a look when you have a chance.
Reeza
Super User

I didn't end up using your code, not sure what it all does. However, my checks does show that the results do match. 

I checked the weighted mean of AGE and BMI and they matched exactly. 

 

ods graphics off;
ods select psinfo varinfo;
proc psmatch data=drugs region=allobs;
   class Drug Gender;
   psmodel Drug(Treated='Drug_X')= Gender Age BMI;
   psweight weight=atewgt nlargestwgt=6;
   assess lps var=(Gender Age BMI)
          / varinfo;
   id BMI;
   output out(obs=all)=OutEx1 weight=_ATEWgt_;
run;


proc sort data=outex1;
by drug;
run;

proc means data=outex1 N MEAN SUM;
    by drug;
    var age bmi ; 
    weight _atewgt_ ;
    output out=mean 
    mean= sum= / autoname;
run;

Results:

 

The PSMATCH Procedure

 
Variable Information
Variable Observations Treated (Drug = Drug_X) Control (Drug = Drug_A) Treated -
Control
N Weight Mean Standard
Deviation
Minimum Maximum N Weight Mean Standard
Deviation
Minimum Maximum Mean
Difference
Logit Prop Score All 113   -0.88062 0.681761 -2.74745 0.58035 373   -1.52059 0.844486 -3.88386 0.78036 0.63997
  Region 113   -0.88062 0.681761 -2.74745 0.58035 373   -1.52059 0.844486 -3.88386 0.78036 0.63997
  Weighted 113 460.45 -1.25406 0.741386 -2.74745 0.58035 373 489.59 -1.35103 0.894234 -3.88386 0.78036 0.09698
Age All 113   36.30973 5.534114 26.00000 49.00000 373   40.40483 6.579103 25.00000 57.00000 -4.09509
  Region 113   36.30973 5.534114 26.00000 49.00000 373   40.40483 6.579103 25.00000 57.00000 -4.09509
  Weighted 113 460.45 38.59813 5.773228 26.00000 49.00000 373 489.59 39.32670 6.771606 25.00000 57.00000 -0.72857
BMI All 113   24.49257 1.863797 20.33000 28.34000 373   23.75327 1.980778 19.22000 28.61000 0.73930
  Region 113   24.49257 1.863797 20.33000 28.34000 373   23.75327 1.980778 19.22000 28.61000 0.73930
  Weighted 113 460.45 24.03522 1.896607 20.33000 28.34000 373 489.59 23.95492 2.004019 19.22000 28.61000 0.08030
Gender All 113   0.43363 0.495575     373   0.45845 0.498270     -0.02482
  Region 113   0.43363 0.495575     373   0.45845 0.498270     -0.02482
  Weighted 113 460.45 0.47335 0.499289     373 489.59 0.45479 0.497952     0.01856

The MEANS Procedure

 
Variable N Mean Sum
Age
BMI
373
373
39.3266975
23.9549166
19253.88
11728.04
 
Variable N Mean Sum
Age
BMI
113
113
38.5981316
24.0352189
17772.51
11067.02

 

Honestly, I don't know what that first table is reporting, at least without some more research but it seems to me the weights are accurately reported.

withyin
Fluorite | Level 6

Thank you Reeza!

 

I guess my question is not just for PROC PSMATCH, but about "weighted mean" in general, including PROC MEANS.

 

Do we calculate the weighted mean of X when Weight = Y by calculating the mean of (X1*Y1, ... Xn*Yn)? 

 

Thanks!

Reeza
Super User
Take a look at the code, you don't try to manually account for it, use the WEIGHT statement and specify that the Y value is your weight. This works for means, but if you're using survey weights you may want to use PROC SURVEYMEANS.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 9 replies
  • 1147 views
  • 2 likes
  • 2 in conversation