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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

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