Hello,
I want to perform proc tabulate with 2 class variables and 1 measurement variable.
I want to modify the report and get the following:
What is the way to do it please?
data have;
input team $ position $ points;
cards;
A Guard 15
A Guard 12
A Guard 29
A Forward 13
A Forward 9
A Forward 16
B Guard 25
B Guard 20
C Guard 34
C Forward 19
C Forward 3
C Forward 8
;
run;
Title 'Distribution-N/SUM of points';
proc tabulate data=have;
class team position;
var points;
table team='' All, position * points='' * (N SUM) /misstext='0' box='Team';
run;
@Ronein, good job describing the problem and your attempts to solve it.
@Ksharp, good solution, but I think you can get by without creating a new variable (but by shuffling pieces of the TABLE statement).
You have:
proc tabulate data=have;
class team p position;
var points;
table team='' All, p=''*(
(position='' all)* N
(position='' all)*points=''*SUM
)/misstext='0' box='Team';
run;
Try it this way:
proc tabulate data=have;
class team position;
var points;
table team='' All, points='Points by Position' * (
(position='' all)* N
(position='' all)*SUM
)/misstext='0' box='Team';
run;
I left the longer label in place for POINTS, rather than trying to explain it. But it can easily be shortened.
data have;
input team $ position $ points;
p='position';
cards;
A Guard 15
A Guard 12
A Guard 29
A Forward 13
A Forward 9
A Forward 16
B Guard 25
B Guard 20
C Guard 34
C Forward 19
C Forward 3
C Forward 8
;
run;
Title 'Distribution-N/SUM of points';
proc tabulate data=have;
class team p position;
var points;
table team='' All, p=''*(
(position='' all)* N
(position='' all)*points=''*SUM
)/misstext='0' box='Team';
run;
@Ronein, good job describing the problem and your attempts to solve it.
@Ksharp, good solution, but I think you can get by without creating a new variable (but by shuffling pieces of the TABLE statement).
You have:
proc tabulate data=have;
class team p position;
var points;
table team='' All, p=''*(
(position='' all)* N
(position='' all)*points=''*SUM
)/misstext='0' box='Team';
run;
Try it this way:
proc tabulate data=have;
class team position;
var points;
table team='' All, points='Points by Position' * (
(position='' all)* N
(position='' all)*SUM
)/misstext='0' box='Team';
run;
I left the longer label in place for POINTS, rather than trying to explain it. But it can easily be shortened.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.