BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

Hi experts, 

I trying to sum up my analysis table using Proc Tabulate. Kindly gothrough the given sample method in detail. 

I want to sum up the Gender variable at the end of OP.

 

data have;
input Type$ Grp$ Sex$;
cards;
1 G F
1 G M
3 O F
3 P M
3 G F
4 P M
7 G M
7 G F
;
proc tabulate data = have;
class Type Grp Sex;
tables Type, Grp*Sex ALL;
keylabel n=' ';
run;

imgss.jpg

 

The result shares the perfect OP values but I required it in the right side displayed tabular format.

Please help me to sum up the Sex variable as the last column in the table. I tried a lot but nothing works well.

Thanks in advance!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
koyelghosh
Lapis Lazuli | Level 10

Try this .. formatting is not exactly correct.. but it is close.

 

PROC REPORT DATA=have;
	COLUMNS Type (Grp , Sex) ('Total' Sex=Sex_Total);
	DEFINE Type / GROUP;
	DEFINE Grp / ACROSS;
	DEFINE Sex / ACROSS;
	DEFINE Sex_Total / ACROSS;
RUN;

The output is as below

OutputOutput

Let me know if this is what you wanted.

View solution in original post

6 REPLIES 6
koyelghosh
Lapis Lazuli | Level 10
Will it matter if you achieve the same result with PROC REPORT instead of PROC TABULATE?
Sathish_jammy
Lapis Lazuli | Level 10

No issues @koyelghosh , Kindly share the details.

Much Thanks!

Ksharp
Super User
data have;
input Type$ Grp$ Sex$;
cards;
1 G F
1 G M
3 O F
3 P M
3 G F
4 P M
7 G M
7 G F
;
proc freq data=have noprint;
table type*grp*sex/out=level sparse list;
run;
proc tabulate data = have classdata=level;
class Type Grp ;
class Sex/order=internal descending;
tables Type=' ', (Grp=' ' ALL)*Sex=' '/box='Type';
keylabel n=' ';
run;
Sathish_jammy
Lapis Lazuli | Level 10

All 3 solutions work well. Thank you so much for your ideas.

Much thanks! @Ksharp  @ballardw  @koyelghosh 

koyelghosh
Lapis Lazuli | Level 10

Try this .. formatting is not exactly correct.. but it is close.

 

PROC REPORT DATA=have;
	COLUMNS Type (Grp , Sex) ('Total' Sex=Sex_Total);
	DEFINE Type / GROUP;
	DEFINE Grp / ACROSS;
	DEFINE Sex / ACROSS;
	DEFINE Sex_Total / ACROSS;
RUN;

The output is as below

OutputOutput

Let me know if this is what you wanted.

ballardw
Super User

Please consider:

data have;
input Type$ Grp$ Sex$;
cards;
1 G F
1 G M
3 O F
3 P M
3 G F
4 P M
7 G M
7 G F
;
proc sort data=have;
  by descending sex;
run;
proc tabulate data = have;
class Type Grp ;
class Sex /order=data;
tables Type, 
      (Grp all='Total')*Sex=' ' 
      /misstext=' '
;
keylabel n=' ';
run;

The ALL would as a minimum need to nest with SEX to get the desired totals. The way shown is one way to do that.

 

Second is to get order of categorical text values can be very problematic as the default order will be FORMATTED and you may have issues getting a SORT order for character values as needed. In this case we could use a sort to get the only "problem" variable Sex and use the Order=data option. More complex order combinations may not work with character values. You've been warned.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 982 views
  • 5 likes
  • 4 in conversation