-1

I have a dataset as follows:

ID |----A---|-----B--| TIME

1--|----1---| ----0---| q1

2--|----0---| ----1---| q2

3--|----0---| ----0---| q3

4--|----1---| ----1---| q4

where 1 means present and 0 means not present

How can I write proc statement to output a frequency table as follows:

          TIME

   Q1             Q2            Q3                   Q4    TOTAL

A

0 ---10---------------20---------------5-------------------3

1----5----------------35---------------2--------------------1

B

0-------1------------2-------------------32-------------------2

1------6--------------3-------------------2-------------------3

Thanks

TS01
  • 3
  • 3
  • 1
    welcome :-) I'm having a hard time understanding the shape of your posted sample data. Can you clarify? – PeterClemmensen Aug 22 '22 at 12:14
  • Yes sorry trying to figure out how to format the table. Is that better – TS01 Aug 22 '22 at 12:17
  • Somewhat better ;-) Question: Where do the values 10, 20, 5 ... come from in your desired table? – PeterClemmensen Aug 22 '22 at 12:20
  • The number of records in A or B with 1s and 0s – TS01 Aug 22 '22 at 12:30
  • Is the output of PROC FREQ not good enough? Did you try PROC TABULATE? – Tom Aug 22 '22 at 12:54
  • So im not too sure how to do proc freq with the 3 columns, one way i've done it is making two seperate proc freq tables one for tables A TIME and one for B TIME. But wondering is there a more efficient way. – TS01 Aug 22 '22 at 13:01

1 Answers1

2

PROC TABULATE is better here as you have a bit more control over the table structure especially with multiple variables.

Something like this - untested because your data is in an unusable form.

proc tabulate data=have;
class a b time;

table a b, (time all='Total');
run;
Reeza
  • 20,510
  • 4
  • 21
  • 38