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 .

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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