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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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