BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chrisgo
Calcite | Level 5

Hi guys, hope you could help me out on this problem:

I have this data set:

COL1               COL2

abc                    def

abc                    xyz

rst                    xyz

what I would want is to have this output:

Summary by COL1:

COL1          COL2

abc               def, xyz

rst                   xyz

Summary by COL2:

COL1          COL2

abc               def

abc,rst            xyz

Thanks and BR,

1 ACCEPTED SOLUTION

Accepted Solutions
JerryLeBreton
Pyrite | Level 9

Try this...

proc transpose data=have out=nearly prefix=x;

   by col1;

   var col2;

run;

data want;

   set nearly;

   col2 = catx(',', of x:);

   keep col1 col2;

run;

... and repeat for the other way round.


View solution in original post

3 REPLIES 3
JerryLeBreton
Pyrite | Level 9

Try this...

proc transpose data=have out=nearly prefix=x;

   by col1;

   var col2;

run;

data want;

   set nearly;

   col2 = catx(',', of x:);

   keep col1 col2;

run;

... and repeat for the other way round.


chrisgo
Calcite | Level 5

Program works. Thanks!

SteveNZ
Obsidian | Level 7

Hiya,

Try:

data have  ;

length col1 col2 $3 ;

infile datalines delimiter=',';

input col1 $ col2 $ ;

datalines;

abc,def

abc,xyz

rst,xyz

;

proc sort data = have ;

by col1 col2 ;

run ;

data want ;

set have ;

by col1 col2 ;

retain col1_summary ;

if first.col1 then col1_summary = catx(',',col2) ;

else col1_summary = catx(',',col1_summary,col2) ;

if last.col1 then output ;

run ;

Repeat above logic to get col2 summary.

cheers

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2825 views
  • 1 like
  • 3 in conversation