질문 내용을 100% 이해하지 못해서... 다음과 같이 해봤습니다.
매크로가 꼭 필요한 것 같지는 않아서 사용하지 않았습니다.
그리고, 20160131부터 시작하는 이유도 잘 모르겠네요. 조건을 적용하면 남는 데이터가 없거든요.
혹 잘못된 부분이나 추가 문의 있으시면 알려주세요.
data work.tmp1;
infile datalines;
input CD:$4. STRT_DT:yymmdd8. TO_DT:yymmdd8.;
format STRT_DT TO_DT yymmddn8.;
datalines;
C001 20181101 20191017
C001 20181101 20191017
C001 20181101 20191017
C001 20181101 20191017
C002 20190501 99991231
C002 20190501 99991231
C002 20190501 99991231
C003 20200305 99991231
C003 20200305 99991231
C003 20191018 99991231
C003 20191018 99991231
C004 20200305 20200511
C004 20200305 20200511
C004 20191101 20200511
C004 20191101 20200511
C005 20200305 99991231
C005 20200305 99991231
C005 20191216 99991231
C006 20200512 20200624
C006 20200512 20200624
C007 20200625 99991231
C007 20200625 99991231
;
run;
data work.end_dt;
mth_end_dt=today();
do until (mth_end_dt='31jan2016'd);
mth_end_dt=intnx('month', mth_end_dt, -1, 'e');
output;
end;
format mth_end_dt yymmddn8.;
run;
proc sql;
create table work.tmp2 as
select ee.*, tt.*
from work.tmp1 tt, work.end_dt ee
where tt.strt_dt<=ee.mth_end_dt and tt.to_dt>=ee.mth_end_dt
order by 1,2
;
quit;
data work.final;
set work.tmp2;
by mth_end_dt cd;
if first.cd;
run;
... View more