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?
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;
I think that you can try 'proc transpose' or use first and last statement by ID
What is the logic here?
And why do you want the wide format?
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.