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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 659 views
  • 0 likes
  • 2 in conversation