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

This is the Data.

 

data one;
input ID Act$ Section$;
datalines;
1 a1 s1
1 a1 s1
1 a2 s3
2 a1 s1
2 a1 s2
2 a1 s3
2 a3 s4
2 a4 s5
3 a1 s1
3 a1 s2
3 a1 s3
;
run;

 

I want this output.

ID      Act_section

1        a1 a2  under/section: s1ss2,s3

2        a1 a3 a4  under/section s1 s2 s3 s4 s5

3        a1 under/section s1 s2 s3.

 

Can you help me? 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data one;
input ID Act$ Section$;
datalines;
1 a1 s1
1 a1 s2
1 a2 s3
2 a1 s1
2 a1 s2
2 a1 s3
2 a3 s4
2 a4 s5
3 a1 s1
3 a1 s2
3 a1 s3
;
run;

data want;
 set one ;
 by id;
 length a b $ 200;
 retain a b;
 if first.id then call missing(a,b);
 if not findw(a,strip(act)) then a=catx(' ',a,act);
 if not findw(b,strip(section)) then b=catx(' ',b,section);
 if last.id then do;act_session=catx(' ',a,'under/section:',b);output;end;
drop a b act section;
run;
proc print;run;

View solution in original post

3 REPLIES 3
juanvg1972
Pyrite | Level 9

I think that you can try 'proc transpose' or use first and last statement by ID

PeterClemmensen
Tourmaline | Level 20

What is the logic here?

 

And why do you want the wide format?

Ksharp
Super User
data one;
input ID Act$ Section$;
datalines;
1 a1 s1
1 a1 s2
1 a2 s3
2 a1 s1
2 a1 s2
2 a1 s3
2 a3 s4
2 a4 s5
3 a1 s1
3 a1 s2
3 a1 s3
;
run;

data want;
 set one ;
 by id;
 length a b $ 200;
 retain a b;
 if first.id then call missing(a,b);
 if not findw(a,strip(act)) then a=catx(' ',a,act);
 if not findw(b,strip(section)) then b=catx(' ',b,section);
 if last.id then do;act_session=catx(' ',a,'under/section:',b);output;end;
drop a b act section;
run;
proc print;run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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