BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I have a table that show for each category the group name.

I want to create another table that will contain for each group one row (so in this case 3 rows).

and for each group there will be information for categories that belong to this group with comma between the value

So the expected table is

USA  200,100,300,400

EU 500,600,150

Asia 250,700

 

Another challenge is to order the value from low to high so the expected table will be

USA  100,200,300,400

EU 150,500,600

Asia 250,700

 

Data tbl1;
Input category group $;
cards;
200 USA
100 USA
300 USA
400 USA
500 EU
600 EU
150 EU
250 Asia
700 Asia
;
run;

1 REPLY 1
Kurt_Bremser
Super User

Sort

by descending group category;

Then, in a data step with

by descending group;

create your new variable with sufficient length, set it to blank at first.group, then do

new_var = catx(',',new_var,category);

and then use a subsetting if for last.group.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 465 views
  • 0 likes
  • 2 in conversation