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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.