BookmarkSubscribeRSS Feed
VD
Calcite | Level 5 VD
Calcite | Level 5


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.

3 REPLIES 3
Reeza
Super User

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

Astounding
PROC Star

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.

VD
Calcite | Level 5 VD
Calcite | Level 5

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;

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
  • 724 views
  • 0 likes
  • 3 in conversation