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

Hi,

 

I've a dataset at school level, and I wanted to run a T test of DAYs by year, weight by cases in each school. The data, SAS code for TTest (with ODS) is as below. The output is fine except the mean statistics is based on weighted mean but the boxplot is based on unweighted mean. Is there a way to fix it?

- I assume it can't do boxplot for weighted data because it CAN"T come up with weighted median, Q1 and Q3? Is it possible for me to plot a boxplot from a data table with those summary statistics? (using unweighted median, Q1 and Q3 and weighted mean).

- I don't actually need boxplot, Just some simple plots showing WEIGHTED mean and confidence interval. Can I produce in the same Ttest procedure? Or other procedures that would do weighted mean plots?

 

Thanks.

 

data have;
input SID 1-4 year cases days;
datalines;
6060 2011 7 1.14286
6190 2011 1 3
6320 2011 3 1
6400 2011 3 1.66667
6740 2011 3 1
6930 2011 5 1.6
7010 2011 3 1.33333
7070 2011 10 1.5
7180 2011 10 1.1
7360 2011 43 1
7530 2011 9 1
7770 2011 7 1.28571
8140 2011 3 1
8370 2011 15 1.13333
8520 2011 30 1.73333
8580 2011 1 1
8980 2011 14 1.14286
9050 2011 80 1.05
9270 2011 15 1.13333
9330 2011 2 1
9350 2011 1 2
9360 2011 22 1.36364
9410 2011 13 1.53846
9420 2011 12 1.33333
9470 2011 8 1
9500 2011 54 1.14815
9510 2011 5 1
9520 2011 4 1.5
9530 2011 104 1.05769
9540 2011 14 1
9550 2011 8 1.125
9570 2011 1 1
9580 2011 10 2.3
9590 2011 23 1.13043
9600 2011 132 1.05303
9620 2011 16 1.125
9650 2011 1 1
9660 2011 55 1
9700 2011 2 2.5
9740 2011 4 1.25
9750 2011 51 1.01961
6060 2015 2 1
6320 2015 6 1.66667
6650 2015 3 1
6740 2015 3 1
6930 2015 2 1
7010 2015 7 2.14286
7070 2015 5 1
7180 2015 8 1
7360 2015 15 1.33333
7450 2015 1 1
7510 2015 11 1
7530 2015 10 1
7770 2015 2 1
8140 2015 15 1.46667
8370 2015 19 1.05263
8520 2015 17 1.70588
8580 2015 1 1
8980 2015 8 1
9050 2015 13 1
9160 2015 4 1
9280 2015 1 1
9300 2015 3 2
9330 2015 1 1
9350 2015 2 1
9360 2015 20 1.35
9410 2015 5 1
9420 2015 10 1
9470 2015 3 1
9500 2015 28 1.03571
9510 2015 5 1
9520 2015 10 1.5
9530 2015 107 1.1215
9540 2015 1 1
9550 2015 10 1.2
9580 2015 1 3
9590 2015 6 1
9600 2015 3 1.66667
9620 2015 26 1.11538
9650 2015 1 2
9660 2015 59 1.0339
9750 2015 5 1.6
9950 2015 1 1
;

ods graphics on;
proc ttest data=have test=diff plots=summary;
class year;
weight Cases;
var days;
ods output equality=VarEqualityTestHSFR TTests=TTestHSFR Statistics=StatsHSFR;
run;
ods graphics off;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I think you get weighted estimates for all statistics with proc sgplot

 


ods graphics on;
proc sgplot data=have;
hbox days / category=year weight=cases;
run;
ods graphics off;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

I think you get weighted estimates for all statistics with proc sgplot

 


ods graphics on;
proc sgplot data=have;
hbox days / category=year weight=cases;
run;
ods graphics off;
PG
Solph
Pyrite | Level 9

Thank so much. It worked perfectly. (The only "complaint" is it seems SGplot does not give statistics. But I can get around getting it elsewhere).

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2288 views
  • 0 likes
  • 2 in conversation