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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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