You don't mention the criteria for determining the LAST 5. So I choose DATE. The IDGROUP option in PROC SUMMARY makes this very easy, assuming that this is what you want. Then you just use CATX to concatenate the 5 new variables.
[pre]
data sched;
input
Course_Code:$4.
Location :$16.
Begin_Date:date.
Teacher &$32.;
format BEG: date9.;
cards;
C001 Seattle 23-Oct-00 Hallis, Dr. George
C002 Dallas 4-Dec-00 Wickam, Dr. Alice
C003 Boston 8-Jan-01 Forest, Mr. Peter
C004 Seattle 22-Jan-01 Tally, Ms. Julia
C005 Dallas 26-Feb-01 Hallis, Dr. George
C006 Boston 2-Apr-01 Berthan, Ms. Judy
C001 Dallas 21-May-01 Hallis, Dr. George
;;;;
run;
proc summary nway;
class course:;
output out=wide(drop=_:)
idgroup(max(Beg:) out[5](teacher)=);
Run;
data wide;
set wide;
length teachers $256;
teachers = catx('; ', of teacher_:);
drop teacher_:;
run;
proc print;
run;
[/pre]
... View more