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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: