DATA Step, Macro, Functions and more

Expanding Date parameter

Reply
Contributor
Posts: 29

Expanding Date parameter

Hi all,

 

Scenario 1:

I have only 2 years (2015, 2016) with start and end dates in data set.

Start

End

201511

201610

 

Now based on above data set is basically range with 2 date (start & End) need to split according to year & month as shown in below table:

S: start date

E: Ending date of that year

S1: continuity of year start

E1: Ending of study date.

Start

End

S

E

S1

E1

201511

201610

201511

201512

201601

201610

 

Scenario 2:

I have only 3 years (2015, 2016, and 2017) with start and end dates in data set.

Start

End

201511

201703

 

Now based on above data set is basically range with 2 date (start & End) need to split according to year & month as shown in below data set table:

S: start date

E: Ending date of that year

S1: continuity of year start

E1: Ending date of that year

S2: continuity of year start

E2: Ending of study date.

 

Start

End

S

E

S1

E1

S2

E2

201511

201610

201511

201512

201601

201612

201701

201703

 

How to create this data set?

 

Thanks,

Ganesh K

Super User
Super User
Posts: 7,976

Re: Expanding Date parameter

Well, this will give you an idea of how to do it.  I couldn't figure out your ending dates logic?  Also, I would as always recommend that having a long structure rather than a wide structure will make oyur coding far easier.

data have;
  start=input("201511",yymmn6.);
  end=input("201610",yymmn6.);
run;
data want;
  set have;
  array s{3} 8;
  array e{3} 8;
  s{1}=start;
  e{1}=end;
  do i=2 to (year(end)-year(start))+1;
    s{i}=intnx('year',start,i-1,'b');
  end;
  format s: e: yymmn6.;
run;
Ask a Question
Discussion stats
  • 1 reply
  • 107 views
  • 0 likes
  • 2 in conversation