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

I want to first group my data by the first variable (borough) and then stratify by the second (sex)  using PROC REPORT. Is this possible to do in one block of code? Switching borough and sex shows a grouped borough variable, but then output is sex*borough instead of borough*sex.

 

option nolabel;
proc report data=freqs headline headskip nowindows ;
column ( borough sex) grps, (WgtN) ;
define borough / group order=internal  ;
define sex / group  order=internal missing   ;
define grps / across nozero order=internal;
define WgtN / analysis;
run;
option label;

Output:

  Group 1 Group 2
borough sex WgtN WgtN
Bronx . 765,159 258,072
  Male 369,787 105,974
  Female 394,607 152,097
Brooklyn . 1,462,698 499,786
  Male 703,190 218,493
  Female 759,333 281,079
Manhattan . 959,070 373,795
  Male 465,047 163,996
  Female 494,023 209,800
Queens . 1,271,159 512,406
  Male 624,295 232,340
  Female 646,864 279,260
Staten Island . 261,142 108,673
  Male 121,637 55,695
  Female 139,505 52,978

 

Want: 

    Group 1 Group 2
borough sex WgtN WgtN
Bronx . 765,159 258,072
Brooklyn . 1,462,698 499,786
Manhattan . 959,070 373,795
Queens . 1,271,159 512,406
Staten Island . 261,142 108,673
Bronx Male 369,787 105,974
  Female 394,607 152,097
Brooklyn Male 703,190 218,493
  Female 759,333 281,079
Manhattan Male 465,047 163,996
  Female 494,023 209,800
Queens Male 624,295 232,340
  Female 646,864 279,260
Staten Island Male 121,637 55,695
  Female 139,505 52,978

 

Thanks. 

1 ACCEPTED SOLUTION

Accepted Solutions
nd
Obsidian | Level 7 nd
Obsidian | Level 7

The dataset is from ods output from PROC FREQ. I realized that I could use the TABLE variable as the grouping value to sort the data appropriately. Thanks for your suggestion. 

View solution in original post

2 REPLIES 2
ballardw
Super User

One of the typical ways to get Proc Report to provide an other than typical display order is to

1) add a variable to your data set whose values will be used to control the order

2) make that variable the first in the column statement

3) on the define for that variable use the Group or Order as normal and add NOPRINT to suppress it from actually appearing the report table output.

 

 

nd
Obsidian | Level 7 nd
Obsidian | Level 7

The dataset is from ods output from PROC FREQ. I realized that I could use the TABLE variable as the grouping value to sort the data appropriately. Thanks for your suggestion. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 504 views
  • 2 likes
  • 2 in conversation