Good evening:
I have data set as:
ID | Eff_DT | TERM_DT |
2987 | 1/1/2022 | 3/31/2022 |
2899 | 1/1/2022 | 2/28/2022 |
2876 | 1/1/2023 | 2/28/2022 |
I need to have out put as:
ID | MONTH | MM |
2987 | 2022-01 | 1 |
2987 | 2022-02 | 1 |
2987 | 2022-03 | 1 |
2899 | 2022-01 | 1 |
2899 | 2022-02 | 1 |
2876 | 2022-01 | 1 |
2876 | 2022-02 | 1 |
Please help
Thank you
data have;
infile cards truncover expandtabs;
input ID Eff_DT : mmddyy10. TERM_DT : mmddyy10.;
format Eff_DT TERM_DT : mmddyy10.;
cards;
2987 1/1/2022 3/31/2022
2899 1/1/2022 2/28/2022
2876 1/1/2022 2/28/2022
;
data want;
set have;
mm=1;
do date=Eff_DT to TERM_DT;
if month(date) ne lag_month then do;month=date;output;end;
lag_month=month(date);
end;
keep id month mm;
format month yymmd7.;
run;
Us a DO loop.
data want;
set have;
retain mm 1 ;
do offset=0 to intck('month',eff_dt,term_dt);
date = intnx('month',eff_dt,offset);
output;
end;
drop eff_dt term_dt;
format date yymm7.;
run;
data have;
infile cards truncover expandtabs;
input ID Eff_DT : mmddyy10. TERM_DT : mmddyy10.;
format Eff_DT TERM_DT : mmddyy10.;
cards;
2987 1/1/2022 3/31/2022
2899 1/1/2022 2/28/2022
2876 1/1/2022 2/28/2022
;
data want;
set have;
mm=1;
do date=Eff_DT to TERM_DT;
if month(date) ne lag_month then do;month=date;output;end;
lag_month=month(date);
end;
keep id month mm;
format month yymmd7.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.