Help using Base SAS procedures

summary values using proc tabulate

Reply
Frequent Contributor
Frequent Contributor
Posts: 94

summary values using proc tabulate


I have two variables (a1 and a2) both with values 0 or 1. I want to get the frequency of 0 and 1 in both the variables along with the percentages. I am trying to get them using proc tabulate but not getting the values. Please could you suggest a solution.

Thanks.

Super User
Posts: 17,724

Re: summary values using proc tabulate

Please post what you've tried and what your data looks like.

Super User
Posts: 5,069

Re: summary values using proc tabulate

You might get PROC TABULATE to do this, but it's easier to let PROC FREQ compute the numbers first.  For example:

proc freq data=have;

   tables a1 / noprint out=a1_counts;

   tables a2 / noprint out=a2_counts;

run;

data all_counts;

   set a1_counts (in=in1)

        a2_counts (in=in2);

   if in1 then varname='a1';

   else if in2 then varname='a2';

run;

Take a look at the results from that much, then use the summary data set as the input to PROC TABULATE.  This is untested code, but should be pretty close to what you want.

proc tabulate data=all_counts;

   class varname a1 a2;
   var count percent;

   tables varname * (a1 a2), count*sum=' ' percent*sum=' ';

run;

Good luck.

Frequent Contributor
Frequent Contributor
Posts: 94

Re: summary values using proc tabulate

Thank you for your replies.

I was hoping to get frequencies of all the variables (a1 and a2) in the same table without having to join them. As you suggested, Proc Freq will ouput different table for each avriable. For this reason I am trying to use proc tabulate.

My dataset looks like:

ID     a1     a2

1      0     1

2     1     1

3      0     0

4     1    1

The output I am looking for is:

          0   1

a1      2    2

a2      1    3

along with the percentages of 0 and 1 in each variable.

I am trying using this code:

proc tabulate data=in    out=out;

class a1 a2;

table  a1*(n) a2*(n);

run;

Ask a Question
Discussion stats
  • 3 replies
  • 183 views
  • 0 likes
  • 3 in conversation