BookmarkSubscribeRSS Feed
bendix
Calcite | Level 5

suppose I have a dataset so that I use

 

proc tabulate  data = a ;

   class a b ;

   table a, b ;

run ;

 

and I get

         b

a      0      1

0      2     4

1      3     1

 

what I want is margins on *both* sides and then percentages of the total on both margins: that is:

 

        b

a       0       1        all

0      20     40       60

1      30     10       40

 all   50     50     100

 

I have a grim suspicion that this is not possible, but I would like to be proven wrong.

 

Bendix Carstensen

Senior Statistician

Steno DIabetes Center Copenhagen

    

 

 

3 REPLIES 3
Shmuel
Garnet | Level 18

Without testing, code should be like:

 

proc tabulate  data = a ;

   class a ;
   var b; 

   table (a all),
         (b all) * (pctn colpctn);

run ;
FloT
Fluorite | Level 6

Hello,

 

You can try this:

proc freq data=a;
	tables a*b / nocol nocum norow nofreq;
run;

I hope this helps,

FloT

ballardw
Super User

@bendix wrote:

suppose I have a dataset so that I use

 

proc tabulate  data = a ;

   class a b ;

   table a, b ;

run ;

 

and I get

         b

a      0      1

0      2     4

1      3     1

 

what I want is margins on *both* sides and then percentages of the total on both margins: that is:

 

        b

a       0       1        all

0      20     40       60

1      30     10       40

 all   50     50     100

 

I have a grim suspicion that this is not possible, but I would like to be proven wrong.

 

Bendix Carstensen

Senior Statistician

Steno DIabetes Center Copenhagen

    

 

 


Provide an actual data set and what the expected results would be.

If you do not provide any additional request in the Table statement of Proc Tabulate then the result for Class variables is a count.

You can request PCTN percentage of table count, RowPctN percentage of row count and ColPctN percentage of column counts.

specific statistic requests may work. I think this is what you are looking for:

data work.a;
   input a b;
datalines;
0 0
0 0
0 1
0 1
0 1
0 1
1 0
1 0
1 0
1 1
;
run;



proc tabulate data=work.a;
   class a b;
   table a all,
         b*(pctn) all*colpctn
   ;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 938 views
  • 4 likes
  • 4 in conversation