BookmarkSubscribeRSS Feed
nelngams
Calcite | Level 5

Dear Community.

 

I am new in SAS and loosing my mind with this.

 

DATA TEST;
INPUT ID UB CONS WGT;
CARDS;
1 0 23 12
2 0 13 10
3 0 21 20
4 0 20 13
5 1 19 12
6 1 24 14
7 0 26 16
8 0 17 10
9 0 19 19
10 1 22 17
11 0 27 10
12 0 18 12
13 1 22 13
14 1 21 20
15 1 20 16
RUN;

 

Where:

  • UB: is a dummy for whether one consumes a given beer or not
  • CONS: is the reported number of bottle drank for a given period of time
  • WGT is my sampling adjustment weight.

 

My data is from an online survey (no design), yet each respondent has a sampling adjustment weight to match the general population.

 

I want to estimate the mean consumption of beer and the corresponding 95% C.I for the two groups of UB (0,1) and test whether consumption is equal between the two groups.

 

Initially I ran this analysis in Stata and now I am tried to replicate it in SAS. I got the same weighted mean but different 95% C.I.

 

STATA Codes: Since STATA does not allow for weighted t-test, I ran a mean estimation (accounting for weight) and used test after mean estimation to compare the two means.

 

. mean CONS [pweight=WGT], over(UB)

. test [CONS]0=[CONS]1

 

. test[CONS]0=[CONS]1
( 1)[CONS]0 - [CONS]1= 0
 F( 1, 14) =0.26
Prob > F =0.6202
 

 

In SAS, I am getting the same means but different 95% Confidence intervals.

 

Analysis Variable : CONS

UB

N Obs

Mean

Lower 95%
CL for Mean

Upper 95%
CL for Mean

0

9

20.6475410

17.5247509

23.7703311

1

6

21.3478261

19.6156577

23.0799944

 

Can some body help with this?

2 REPLIES 2
Rick_SAS
SAS Super FREQ

What SAS code did you use? That looks like PROC MEANS output. I suggest you use PROC SURVEYMEANS (if you want to correct for the survey nature) or PROC TTEST.

 

PROC TTEST with a WEIGHT WGT statement gives the same output, but also provides statistical tests for the difference of the means between the two groups. From the data, I would not assume that the variances are equal, which suggests using the Satterthwaite test results. The test statistic and p-value are close to the stata estimate you constructed.

 

 

PaigeMiller
Diamond | Level 26
proc means data=have;
    class ub;
    var cons;
    weight wgt;
run;

By the way, there's no reason to expect SAS and STATA will produce the exact same results, although it certainly is possible in this example.

 

Cheers to UB (University at Buffalo) for winning their first ever NCAA Football Bowl Game!

--
Paige Miller

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 568 views
  • 0 likes
  • 3 in conversation