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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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