BookmarkSubscribeRSS Feed
madhu
Calcite | Level 5

I need to group values in  variable - and Arrive at the following Output

Input -

Header 1Header 2Header 3
Sub 1101102
Sub 1124125
Sub 1175176
Sub 2201202
Sub 2275276
Sub 2295296


Output -

Header 1Header 2
Sub 1101, 102, 124, 125, 175, 176
Sub 2201, 202, 275, 276, 295, 296


Thanks in Advance.

4 REPLIES 4
Linlin
Lapis Lazuli | Level 10

Hi madhu,

I am sure there are better ways to solve your problem. I will post my code anyway.

data have;

input header1 $ var1 var2;

cards;

Sub1 101 102

Sub1 124 125

Sub1 175 176

Sub2 201 202

Sub2 275 276

Sub2 295 296

;

run;

proc transpose data=have out=want21 ;

by header1;

var var1;

run;

proc transpose data=have out=want22 prefix=n;

by header1;

var var2;

run;

data want(keep=header1 header2) ;

  merge want21 want22;

  by header1;

     array v(*) col1-col3 n1-n3;

     call sortn(of v(*));

       header2=catx(',',of v(*));

  run;

Peter_C
Rhodochrosite | Level 12

and in a single pass:

data want (keep= header1 header2 compress=yes ) ;

do until( last.header1 ) ;

   set have ;

   by header1 ;

   length header2 $32760 ;

  header2 = catx( ',', header2, var1, var2 ) ;

end ;

run ;

Linlin
Lapis Lazuli | Level 10

Thank you Peter! have a nice weekend!

madhu
Calcite | Level 5

Thanks Peter and Linlin

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!

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
  • 4 replies
  • 1152 views
  • 0 likes
  • 3 in conversation