The sample data you're using illustrates why you shouldn't code "else do; flag = 'last week' ; end;" but should calculate "last week" and then eventually have an other case like "else flag='earlier weeks' " Below a code sample based on your code but using a format instead. data fmt_source; format start date9.; length label $20.; retain fmtname 'WeekGroup'; retain type 'N'; do start=intnx('year',today(),-1) to today(); week=intck('week',start,today()); select(week); when(0) label='This Week'; when(1) label='Last Week'; otherwise label=catx(' ',week,'weeks ago'); end; output; end; run; proc format cntlin=fmt_source; run; data src_rec; input name $ sex $ school $ dt date9. score; datalines; AAA F Law 9-sep-14 10 BBB F IT 10-Aug-14 20 CCC M Law 19-Sep-14 30 DDD F Art 10-Dec-14 25 EEE F Law 9-sep-14 40 FFF M Biz 10-Aug-14 45 GGG F Law 9-Dec-14 55 HHH M IT 6-Dec-14 50 III M Law 19-Nov-14 45 JJJ M Art 10-Aug-14 20 kkk F Law 9-Dec-14 25 lll F Biz 8-Dec-14 20 ; run; proc tabulate data = src_rec order=unformatted; class school sex dt; var score; format dt WeekGroup.; table (school*sex ),dt='No of student Registered'*n=''(dt='Sum of score'*score=''*sum='')(dt='Avg of score'*score=''*mean=''); run;
... View more