Help using Base SAS procedures

PROC TABULATE: Percentages of Analysis Variables

Reply
Contributor
Posts: 62

PROC TABULATE: Percentages of Analysis Variables

Hi everyone,

I was wondering if one can help with this proc tabulate code if it's possible to do at all!

I'm trying to get percentage of each analysis variable within the first row heading.

I put the code and attached an outcome doc.

I am cross tabulating vis (for visit) with flags for visit status (comp, miss, pending, drop). I'm setting each of these status variables as an "analysis" variable using VAR statement.

and trying to get percentage of each status from the (total within each visit, ie. not from the overall total  )

data have;

input comp miss pending drop vis id;

cards;

   .       .        1         .      3     001

   1       .        .         .      1     002

   1       .        .         .      2     002

   1       .        .         .      3     002

   1       .        .         .      1     003

   1       .        .         .      2     003

   1       .        .         .      3     003

   1       .        .         .      1     004

   .       1        .         .      2     004

   1       .        .         .      3     004

   1       .        .         .      1     005

   1       .        .         .      2     005

   1       .        .         .      3     005

   1       .        .         .      1     006

   1       .        .         .      2     006

   .       .        1         .      3     006

   .       .        1         .      3     007

   .       1        .         .      1     008

   .       1        .         .      2     008

   .       .        1         .      3     008

   1       .        .         .      1     009

   1       .        .         .      2     009

   .       .        1         .      3     009

   1       .        .         .      1     010

   .       .        1         .      2     010

   .       .        1         .      3     010

   .       .        .         1      1     011

   .       .        .         1      2     011

   .       .        .         1      3     011

   .       .        1         .      1     012

   .       .        1         .      2     012

   .       .        1         .      3     012

   .       .        1         .      1     013

   .       .        1         .      2     013

   .       .        1         .      3     013

   1       .        .         .      1     014

   1       .        .         .      2     014

   1       .        .         .      3     014

run;

proc tabulate data=have  missing format=6. ;

  class vis ;

  var comp miss pending  drop;

  tables vis *( n (comp miss pending  drop)*(sum='' ) ), all /rts=30 row=float;

run;

/*** I'm trying to obtain percentage of each status each visit using the code below, but the percentage

     I'm getting is for the flag within itself not within the visit  ***/

proc tabulate data=have   format=6. ;

  class vis ;

  var comp miss pending  drop;

  tables vis *( n (comp miss pending  drop)*(sum=''  pctn<vis all >) ), all /rts=30 row=float;

run;

so for example, for the first visit, for comp, I wanna get percentage of 8/12=66.6% and so on... instead I'm getting 42% which is 8/19 (and 19 is the total number of comp=1 in the dataset)

Thanks

Super User
Posts: 11,343

Re: PROC TABULATE: Percentages of Analysis Variables

One way is to code all those missing to 0 then use

tables vis *( n (comp miss pending  drop)*(sum=''  mean='%'*f=perecent8.) ), all /rts=30 row=float;

Contributor
Posts: 62

Re: PROC TABULATE: Percentages of Analysis Variables

Yes; that would work

data have;

  set have;

  comp=sum(comp,0);miss=sum(miss,0); pending=sum(pending,0); drop=sum(drop,0);

run;

proc tabulate data=have   format=6. ;

  class vis ;

  var comp miss pending  drop;

  tables vis *( n (comp miss pending  drop)*(sum=''  mean='%'*f=percent.) ), all /rts=30 row=float;

run;

Is there a way to do it without converting the missing to zeros?

Contributor
Posts: 64

Re: PROC TABULATE: Percentages of Analysis Variables

Hi,

I think,

If we do not convert them into zero it will take only the non-miss value observations for the calculation, then the percentage will change what we need...

I faced same problem once but, I got what I required without converting missing to zeros.

Please correct if i am wrong..  Ballardw or Altal.

Super User
Posts: 11,343

Re: PROC TABULATE: Percentages of Analysis Variables

Posted in reply to DR_Majeti

The Proc Tabulate ability to specify denominators for percentage calculations is limited. Depending on the way you want your final table to look sometimes the PCTN< > or PCTSUM<> just don't work. I often use the 0/1 coding for the analysis variables as then I can get expected N, Sum and Mean for percent without much difficulty though I usually use a custom format instead of PercentX. display in the manner I want.

About 80% of my cases of crashing SAS involve attempts to get PCTN or PCTSUM to work as apparently some of the combinations aren't valid but are not invalid in the syntax checker.

Ask a Question
Discussion stats
  • 4 replies
  • 354 views
  • 3 likes
  • 3 in conversation