BookmarkSubscribeRSS Feed
lin39
Obsidian | Level 7

Hi SAS experts,

 

I have a dataset that has gender groups (0, 1) nested in departments.

I'd like to use Proc Tabulate to generate some reports by department and by gender. 

 

Here is what I need to produce:

 

Table 1:

Account department, Male

N, 1 Year Retention, 2 Year Retention

20, 20%, 30%

 

Table 2:

Account department, Female

N, 1 Year Retention, 2 Year Retention

40, 22%, 30%

 

Table 3:

Payroll department, Male

N, 1 Year Retention, 2 Year Retention

40, 21%, 10%

 

etc. etc..

 

However, using proc tabulate

by department gender ;

 

Gives me tables in the following undesired order:

 

Account department, Male

Payroll department, Male

Account department, Female

Payroll department, Female

etc.

 

I really want:

Account department, Male

Account department, Female

Payroll department, Male

Payroll department, Female

 

How do I fix this?

 

Thanks so much!

 

 

 

3 REPLIES 3
jklaverstijn
Rhodochrosite | Level 12

From what you write your output should be as desired. Do your variables have formats perhaps? The ordering can be accordiung to unformatted values. Anyways please share your code and data. No doubt with more info the issue will be resolved quickly. 

 

Regards, Jan.

ballardw
Super User

Show the exact code you used. The order of variables in the table statement is important. And while Tabulate will supporat BY variables often it is best to use those as CLASS variables and provide them in a page dimension.

Order of appearance will depend upon Order=options and the order variables appear in parts of the proc.

 

If you provide some example data in the form of a datastep we can test and provide exact code.

Ksharp
Super User
1)Use proc tabulate option :   Order=DATA 
2)Padding some white blank before the value to customize the order .

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

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