Desktop productivity for business analysts and programmers

Combining rows of data under new subheadings

Reply
Occasional Contributor
Posts: 13

Combining rows of data under new subheadings

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!

Super User
Posts: 5,365

Re: Combining rows of data under new subheadings

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".

Occasional Contributor
Posts: 13

Re: Combining rows of data under new subheadings

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

Super User
Posts: 5,365

Re: Combining rows of data under new subheadings

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;

Ask a Question
Discussion stats
  • 3 replies
  • 190 views
  • 0 likes
  • 2 in conversation