BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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:

Ronein_0-1660032462566.png

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; 
 
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

@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.

View solution in original post

4 REPLIES 4
Ksharp
Super User
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; 

Ksharp_0-1660048052736.png

 

Astounding
PROC Star

@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.

Ronein
Onyx | Level 15
Thanks
May you please explain what is the meaning of p? As i see it is a new variable that you defined?
Ksharp
Super User
p has value 'position' for all the obs, It is a dummy variable to make the top header 'position'.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 975 views
  • 3 likes
  • 3 in conversation