BookmarkSubscribeRSS Feed
Ganeshk
Obsidian | Level 7

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

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 1 reply
  • 676 views
  • 0 likes
  • 2 in conversation