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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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