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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 598 views
  • 4 likes
  • 4 in conversation