BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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;

 

Ksharp
Super User
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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1009 views
  • 0 likes
  • 3 in conversation