DATA Step, Macro, Functions and more

Get standard deviation of sum using weights in PROC TABULATE

Reply
New Contributor
Posts: 4

Get standard deviation of sum using weights in PROC TABULATE

Hi there,

 

I was wondering if there is a way to add a column with the std dev next to the sum of certain variables in PROC TABULATE. I only seem to get the STD to work when i am calculating the mean value of variables but I use weights to calculate the sum of variables and I want to include the standard deviation of using those weights (basically the same standard deviation number you get when u use surveymeans to calculate the number of occurrences a variable appears).

 

I have tried putting the WEIGHT statement in various places, I've tried using the vardef=weight but nothing seems to work.

 

Here is my code

 

PROC TABULATE
DATA=kid.prs (where=(PRS=1));
    VAR total;
    CLASS FEMALE /    ORDER=UNFORMATTED MISSING;
    CLASS race /    ORDER=UNFORMATTED MISSING;
    CLASS hosp_division /    ORDER=UNFORMATTED MISSING;
    CLASS zipinc /    ORDER=UNFORMATTED MISSING;
    CLASS dispuniform /    ORDER=UNFORMATTED MISSING;
    CLASS hosp_locteach /    ORDER=UNFORMATTED MISSING;
    CLASS gtube /    ORDER=UNFORMATTED MISSING;
    CLASS MDO /    ORDER=UNFORMATTED MISSING;
    CLASS TLA /    ORDER=UNFORMATTED MISSING;
    CLASS Trach /    ORDER=UNFORMATTED MISSING;
    CLASS syndromic /    ORDER=UNFORMATTED MISSING;
    keyword all sum / style=[fontwidth=wide];
   keylabel all="Total";
    TABLE /* Row Dimension */
FEMALE RACE hosp_division zipinc dispuniform hosp_locteach,
/* Column Dimension */
Total*(gtube)*(Sum='N'*f=comma12.0 ColPctSum='%'*f=pctf.) / nocellmerge;    
        
    ;
    WEIGHT DISCWT;
    Format race racef.;
    Format female femalef.;
    Format hosp_division divisionf.;
    Format zipinc zipincf.;
    Format dispuniform dispf.;
        Format hosp_locteach hosp_locteachf.;

RUN;

 

Super User
Posts: 13,066

Re: Get standard deviation of sum using weights in PROC TABULATE

Total*(gtube)*(Sum='N'*f=comma12.0 ColPctSum='%'*f=pctf.  std) 

should give you the standard deviation of gtube using weights.

 

New Contributor
Posts: 4

Re: Get standard deviation of sum using weights in PROC TABULATE

That doesn't work. It seems as if the STD only works for means/median calculations not the sum calculation

Ask a Question
Discussion stats
  • 2 replies
  • 88 views
  • 0 likes
  • 2 in conversation