BookmarkSubscribeRSS Feed
ywon111
Quartz | Level 8

Hi - is there a way to group observations together, i.e. if fruit is variable and i want to group apple and orange as Group 1 to show in output report?

 

This is what I got now:

 

Example of data:

Fruit

Apple

Orange

Grapes

Banana

 

proc report data=final;
columns fruit n;
define fruit/group;
define n /'Count';
rbreak after / summarize;
run;

 

 

2 REPLIES 2
ketpt42
Quartz | Level 8

I think you would need a column in your final dataset that contains the grouping information you are looking to group by in the proc report.

 

CATEGORY

FRUIT COUNT
Group 1 Apple

10

Group 1 Orange 20
Group 2 Grapes 15
Group 2 Banana 5

 

Then you could define CATEGORY as a group variable. 

Cynthia_sas
SAS Super FREQ

Hi:

  Here's an example using SASHELP.CLASS. Suppose you want to put the students into 2 categories -- Yes or No -- are they eligible for Driver's Ed based on their age. You can do that with a user defined format:

 

Cynthia_sas_0-1594391741313.png

Now the user-defined format is just the beginning. It only defines how the ages get broken up into categories. Now the format needs to be used. This is the output I want to create:

Cynthia_sas_1-1594391805242.png

Notice that I have a sub-category of M and F for the male and female students and I'm getting a count of each gender within each age category. I've also added subtotals of count and a grand total for all students at the bottom of the report.

 

  Here's the PROC REPORT code that does everything in one step. Since age is a numeric variable, I wanted to make a helper column to hold the category value and the longer text on the break lines. That was all accomplished in the COMPUTE block for AGECAT, my helper variable:

Cynthia_sas_2-1594392024862.png

Hope this helps point you toward one possible solution with PROC REPORT.

Cynthia

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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