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

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
Meteorite | Level 14
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'.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 502 views
  • 3 likes
  • 3 in conversation