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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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