Udhai kumar
Udhai kumar

Reputation: 43

how to create a table in sas to view the count of column variable with respect to another?

I have data set as follows:

id a b
1  1 1
2  3 4
3  1 0
4  2 3

Where a and b have values (0-4).I want to create a view like this:

a/b 0 1 2 3 4
0   3 5 0 0 0
1   4 4 0 0 0
2   2 3 0 0 6

Basically i want to get count of a with respect to b. How can i create view in sas ?

Upvotes: 0

Views: 124

Answers (1)

Richard
Richard

Reputation: 27498

You can present the counts using Proc TABULATE with CLASSDATA option for completeness.

Example:

data have;
  call streaminit(123);
  do id = 1 to 1000;
    a = rand('integer',0,4);
    do until (b ne 3);
      b = rand('integer',0,4);
    end;

    output;
  end;
run;

data allpairs;
  do a = 0 to 4;
  do b = 0 to 4;
    output;
  end;
  end;
run;

ods html file='output.html' style=plateau;

options missing = '0';

proc tabulate data=have classdata=allpairs;
  class a b;
  table a=' ', b*n=' '*[style=[textalign=center cellwidth=3em]] / box='a';
run;

ods html close;

Output:
enter image description here

Upvotes: 1

Related Questions