Background: for my dataset I produce a contingency table with proc TABULATE of all case characteristics crossed with the type of clinic they attended (3-levels). In the contingency table I also have SAS calculate the percentage of cases using the denominator of the clinic-type level.

Problem: The problem is, when I calculate the percentage by hand using the printed SAS frequencies I get a slightly different percentage that what SAS calculates. For example, SAS says that males make up 52.5% (N=1205) of all non-STD clinic attendees (N=2326), but when I calculate that percentage I get 1205/2326= .518, 51.8%, (which is about 9.8% off). I am wondering if SAS is calculating the percentage of the unweighted clinic types denominator, but using the weighted characteristic frequency?

Question:

1) am I correctly weighting my dataset? I found information here: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473744.htm and it looks like instead of using "var wtcap" I should use the "weight wtcap" statement, but even when I do this I still get percentages that differ from the SAS contingency table compared to my hand-calculated values. Not to mention, when I use the "weight wtcap" statement the cell frequencies are much larger. Should I be using proc SURVEYFREQ?

2) does anyone know how to use the weighted value for the denominator of the percentage other than using the weight statement which I am using with the line " var wtcap" (or, if that statement is wrong, then "weight wtcap") when running proc TABULATE?

See my current code below:

/*Print Frequency TABLE CHARACTERISITICS*/

options nodate nonumber;

proc tabulate data= std.case MISSING ;

KEYLABEL N="Total cases" ALL="Total cases" PCTN="%" sum=" ";

var wtcap;

label wtcap="cases (weighted)";

class /*demographics*/ GENDER2 AGEGR2 RACE2B ATTND;

classlev /*demographics*/ GENDER2 AGEGR2 RACE2B ATTND;

TABLE ALL /*demographics*/ GENDER2 AGEGR2 RACE2B

,

(ATTND*(wtcap*f=4.2 pctn<ALL

/*demographics*/ GENDER2 AGEGR2 RACE2B>*f=4.1)) ALL;

RUN;

Thanks for any advice!

Lucy

Problem: The problem is, when I calculate the percentage by hand using the printed SAS frequencies I get a slightly different percentage that what SAS calculates. For example, SAS says that males make up 52.5% (N=1205) of all non-STD clinic attendees (N=2326), but when I calculate that percentage I get 1205/2326= .518, 51.8%, (which is about 9.8% off). I am wondering if SAS is calculating the percentage of the unweighted clinic types denominator, but using the weighted characteristic frequency?

Question:

1) am I correctly weighting my dataset? I found information here: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473744.htm and it looks like instead of using "var wtcap" I should use the "weight wtcap" statement, but even when I do this I still get percentages that differ from the SAS contingency table compared to my hand-calculated values. Not to mention, when I use the "weight wtcap" statement the cell frequencies are much larger. Should I be using proc SURVEYFREQ?

2) does anyone know how to use the weighted value for the denominator of the percentage other than using the weight statement which I am using with the line " var wtcap" (or, if that statement is wrong, then "weight wtcap") when running proc TABULATE?

See my current code below:

/*Print Frequency TABLE CHARACTERISITICS*/

options nodate nonumber;

proc tabulate data= std.case MISSING ;

KEYLABEL N="Total cases" ALL="Total cases" PCTN="%" sum=" ";

var wtcap;

label wtcap="cases (weighted)";

class /*demographics*/ GENDER2 AGEGR2 RACE2B ATTND;

classlev /*demographics*/ GENDER2 AGEGR2 RACE2B ATTND;

TABLE ALL /*demographics*/ GENDER2 AGEGR2 RACE2B

,

(ATTND*(wtcap*f=4.2 pctn<ALL

/*demographics*/ GENDER2 AGEGR2 RACE2B>*f=4.1)) ALL;

RUN;

Thanks for any advice!

Lucy

Last edited: