BookmarkSubscribeRSS Feed
jsimmo02
Calcite | Level 5

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;

 

2 REPLIES 2
ballardw
Super User
Total*(gtube)*(Sum='N'*f=comma12.0 ColPctSum='%'*f=pctf.  std) 

should give you the standard deviation of gtube using weights.

 

jsimmo02
Calcite | Level 5

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

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 1828 views
  • 0 likes
  • 2 in conversation