sas

Proc Tabulate rowpctn separate column percent


I am new to SAS, try to figure out Proc Tabulate more.

proc tabulate data=stem_camp1;
class gender pass SUBJECT;
table GENDER, SUBJECT*PASS*(n="count" rowpctn="%");
run;

I have a code like this above.

enter image description here SAS is calculating percentage BIOS AND MATH, so when I sum up 4 of %, it gets 100%

but I want SAS to calculate percentage BIOS AND MATH separate.

for example like this

       BIOS                 MATH
MALE - - 10 100%      10 50%  10 50%  

Solution

  • From helps (my bold):

    Using PCTN and PCTSUM

    PCTN and PCTSUM statistics can be used to calculate these same percentages. They enable you to manually define denominators. PCTN and PCTSUM statistics print the percentage of the value in a single table cell in relation to the value (used in the denominator of the calculation of the percentage)in another table cell or to the total of the values in a group of cells. By default, PROC TABULATE summarizes the values in all N cells(for PCTN) or all SUM cells (for PCTSUM) and uses the summarized value for the denominator. You can control the value that PROC TABULATE uses for the denominator with a denominator definition.

    You place a denominator definition in angle brackets (< and >) next to the PCTN or PCTSUM statistic. The denominator definition specifies which categories to sum for the denominator.

    So you will want PCTN<PASS> instead of ROWPCTN.

    Here is an example using data set sashelp.cars

    proc tabulate data=sashelp.cars;
      class type origin drivetrain;
      table type, origin*drivetrain*(n pctn<drivetrain>);
    run;
    

    enter image description here

    Just to be clear, the ALL drivetrain means All Wheel Drive, and is not the Universal Class Variable ALL.