BookmarkSubscribeRSS Feed
jos283
Fluorite | Level 6

Is there a way to combine/group similar rows and place them under a new sub-category?

Ignore the bold/underline formatting, they're just to help you understand the column heading and subcategory headings.

Let's say the dataset looks like the following with column Food:

 

Food                                               Column 2          Column 3 etc (continues till Column 50+)

Apple

Banana

Burger

Crepe

Strawberry

Fries

Pear

Ice Cream

(rows continue for 1000+)

 

And I want the output to look like:

 

Food                                               Column 2          Column 3 etc (continues till Column 50+)

Fruits (like a drop down menu)

Apple

Banana

Strawberry

Pear

(etc.)

Unhealthy

Burger

Fries

(etc.)

Dessert

Ice Cream

Crepe

(etc.)

 

Don't really have a clue how to code this or where to begin. Maybe a Proc Report or Proc Sql?

Help is greatly appreciated!

3 REPLIES 3
Astounding
PROC Star

You can generate a report that looks like what you want.  But you first have to add a column to the data.  A new variable would take on values like "Fruits", "Unhealthy", or "Dessert".

jos283
Fluorite | Level 6

How would I go about creating a report? Don't seem to see anywhere on the application

Astounding
PROC Star

What application are you referring to?

 

If you are programming this, it might (depending on what the report should contain) go like this:

 

proc sort data=have;

by new_variable_with_food_category;

run;

 

proc print data=have;

by new_variable_with_food_category;

id new_variable_with_food_category;

var food column2 column3 ... column50;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1378 views
  • 0 likes
  • 2 in conversation