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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 773 views
  • 2 likes
  • 4 in conversation