<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to convert data from underwriting year basis to calendar year basis? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728694#M28288</link>
    <description>&lt;P&gt;You are overcomplicating things, all you need is a DO loop and some cleanup for the final year:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ (start_date end_date) (:date9.) exposure amount;
format start_date end_date yymmdd10.;
datalines;
1111 01jul2015 20jun2021 6 5000
1112 01jan2017 31dec2020 4 3500
1113 01mar2018 29feb2020 2 7000
;

data want;
set have;
format
  begprdx endprdx yymmdd10.
  adj_amount 20.2
  adj_exposure 5.2
;
endprdx = min(end_date,intnx('year',start_date,0,'e'));
do while (endprdx lt end_date);
  begprdx = max(start_date,intnx('year',endprdx,0,'b'));
  adj_exposure = ((endprdx - begprdx) / 365);
  adj_amount = (amount / (end_date - start_date + 1)) * (endprdx - begprdx + 1);
  output;
  endprdx = min(end_date,intnx('year',endprdx,1,'e'));
end;
begprdx = max(start_date,intnx('year',end_date,0,'b'));
adj_exposure = round(endprdx - begprdx) / 365;
adj_amount = (amount / (end_date - start_date + 1)) * (endprdx - begprdx + 1);
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that data has to be presented in a data step with datalines; we can't write SAS programs for pictures.&lt;/P&gt;
&lt;P&gt;Please provide your example data in this form in the future, see it as a basic courtesy for those who are intended to help you.&lt;/P&gt;
&lt;P&gt;And you'll get answers quicker, because we do not have to waste time writing the data step ourselves.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 09:13:09 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-03-24T09:13:09Z</dc:date>
    <item>
      <title>How to convert data from underwriting year basis to calendar year basis?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728673#M28283</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to seek your assistance in guiding me on how to convert/transform the data from underwriting year to calendar year as shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Underwriting Year basis:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_test1.png" style="width: 488px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56385i099365449B27AC46/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas_test1.png" alt="sas_test1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have now is splitting the data up to 2 years of exposure with the following SAS code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA CALYR_SPLIT (DROP=Z_BEGPRD Z_ENDPRD BEGPRD1 BEGPRD2 BEGPRD3 
		ENDPRD1 ENDPRD2 ENDPRD3 VARX DURATION1 DURATION2 DURATION3 DURATIOND 
		PORTION1 PORTION2 PORTION3 YEARD);

	SET ININ.TEST;

	FORMAT BEGPRDX ENDPRDX DDMMYY10.;
	FORMAT ADJ_AMOUNT ADJ_EXPOSURE 10.2;
		
	FORMAT Z_BEGPRD Z_ENDPRD DDMMYY10.;
	FORMAT PORTION1 PORTION2 PORTION3 PERCENT10.2;

	YEARD = YEAR(END_DATE) - YEAR(START_DATE);

/*********************	FOR 1-YEAR COVERAGE*************************************/
	IF YEARD = 1 THEN DO;	
		Z_BEGPRD = INTNX('YEAR', START_DATE, 0, 'END');
		Z_ENDPRD = INTNX('YEAR', END_DATE, 0, 'BEGINNING');

		DURATION1 = INTCK('DAY', START_DATE, Z_ENDPRD);
		DURATION2 = INTCK('DAY', Z_BEGPRD, END_DATE);
		DURATION3 = .;
		DURATIOND = DURATION1 + DURATION2;

	/******	USED IN ARRAYS********/
		BEGPRD1 = START_DATE;
		BEGPRD2 = INTNX('YEAR', END_DATE, 0, 'BEGINNING');
		ENDPRD1 = INTNX('YEAR', START_DATE, 0, 'END');
		ENDPRD2 = END_DATE;
		PORTION1 = DURATION1/DURATIOND;
		PORTION2 = DURATION2/DURATIOND;

		VARX = 1;
		ADJ_AMOUNT = 0;
		ADJ_EXPOSURE = 0;
			
		ARRAY PORT1 [2] PORTION1 PORTION2;
		ARRAY BEG1 [*] BEGPRD1 BEGPRD2;
		ARRAY END1 [*] ENDPRD1 ENDPRD2;

		DO UNTIL (VARX GT 2);
			BEGPRDX = BEG1[VARX];
			ENDPRDX = END1[VARX];
			ADJ_AMOUNT = AMOUNT*PORT1[VARX];
			ADJ_EXPOSURE = EXPOSURE*PORT1[VARX];
			VARX = VARX + 1;
		OUTPUT;
		END;
	END;

/*********************	FOR COVERAGES THAT ARE MORE THAN 1 YEAR LONG*********************/
	ELSE IF YEARD = 2 THEN DO;
		IF (MOD((YEAR(END_DATE) - 1),4)) = 0 THEN DURATION2 = 366;
		ELSE DURATION2 = 365; 
			
		Z_BEGPRD = INTNX('YEAR', START_DATE, 1, 'END');
		Z_ENDPRD = INTNX('YEAR', END_DATE, -1, 'BEGINNING');

		DURATION1 = INTCK('DAY', START_DATE, Z_ENDPRD);
		DURATION3 = INTCK('DAY', Z_BEGPRD, END_DATE);
		DURATIOND = DURATION1 + DURATION2 + DURATION3;
			
		BEGPRD1 = START_DATE;
		BEGPRD2 = INTNX('YEAR', END_DATE, -1, 'BEGINNING');
		BEGPRD3 = INTNX('YEAR', END_DATE, 0, 'BEGINNING');

		ENDPRD1 = INTNX('YEAR', START_DATE, 0, 'END');
		ENDPRD2 = INTNX('YEAR', END_DATE, -1, 'END');
		ENDPRD3 = END_DATE;

		PORTION1 = DURATION1/DURATIOND;
		PORTION2 = DURATION2/DURATIOND;
		PORTION3 = DURATION3/DURATIOND;

		VARX = 1;
		ADJ_AMOUNT = 0;
		ADJ_EXPOSURE = 0;
			
		ARRAY PORT2 [*] PORTION1 PORTION2 PORTION3;
		ARRAY BEG2 [*] BEGPRD1 BEGPRD2 BEGPRD3;
		ARRAY END2 [*] ENDPRD1 ENDPRD2 ENDPRD3;

		DO UNTIL (VARX GT 3);
			BEGPRDX = BEG2[VARX];
			ENDPRDX = END2[VARX];
			ADJ_AMOUNT = AMOUNT*PORT2[VARX];
			ADJ_EXPOSURE = EXPOSURE*PORT2[VARX];
			VARX = VARX + 1;
			OUTPUT;
		END;
	END;

/*********************	FOR COVERAGE 1 YEAR (1 JAN YYYY TO 31 DEC YYYY)*****************/
	ELSE DO;		
		BEGPRDX = START_DATE;
		ENDPRDX = END_DATE;
		ADJ_AMOUNT = AMOUNT;
		ADJ_EXPOSURE = EXPOSURE;
		OUTPUT;
	END;	
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and my current output is this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_test.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56384iF16F986024877F22/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas_test.png" alt="sas_test.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advise on how to split for the observations with &amp;gt; 2 years of exposure as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 06:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728673#M28283</guid>
      <dc:creator>Ad_1993</dc:creator>
      <dc:date>2021-03-24T06:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert data from underwriting year basis to calendar year basis?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728676#M28284</link>
      <description>&lt;P&gt;What does your desired result look like given the input data ?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 06:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728676#M28284</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-03-24T06:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert data from underwriting year basis to calendar year basis?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728678#M28285</link>
      <description>&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;From my current output attached beneath the SAS code I shared, you will see that the ID with 2 years of exposure is successfully split into calendar year basis. I would like the same result like this for the ID with 6 years and 4 years of exposure respectively.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps something like this (The following sample output was computed in Excel and imported into SAS for your reference):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sample_output.png" style="width: 864px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56386iF70A0F499F0165A9/image-size/large?v=v2&amp;amp;px=999" role="button" title="sample_output.png" alt="sample_output.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 07:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728678#M28285</guid>
      <dc:creator>Ad_1993</dc:creator>
      <dc:date>2021-03-24T07:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert data from underwriting year basis to calendar year basis?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728684#M28286</link>
      <description>&lt;P&gt;Is&amp;nbsp; that what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
     save_end_date = end_date;
	 start_year = year(start_date);
	 end_year = year(end_date);
	 drop save_end_date start_year end_year;
	 
     if end_year = start_year then output;
	 else do;
	    end_year = start_year;
     	do util (end_year = year(save_end_date));
	    if end_year = year(save_end_date)
		   then end_date = save_end_date;
	       else end_date = mdy(12,31,start_year +1);
		end_year = end_year +1;
		output;
	    start_date = mdy(01,01,end_year);
		start_year = year(start_date);
	 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 08:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728684#M28286</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-24T08:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert data from underwriting year basis to calendar year basis?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728694#M28288</link>
      <description>&lt;P&gt;You are overcomplicating things, all you need is a DO loop and some cleanup for the final year:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ (start_date end_date) (:date9.) exposure amount;
format start_date end_date yymmdd10.;
datalines;
1111 01jul2015 20jun2021 6 5000
1112 01jan2017 31dec2020 4 3500
1113 01mar2018 29feb2020 2 7000
;

data want;
set have;
format
  begprdx endprdx yymmdd10.
  adj_amount 20.2
  adj_exposure 5.2
;
endprdx = min(end_date,intnx('year',start_date,0,'e'));
do while (endprdx lt end_date);
  begprdx = max(start_date,intnx('year',endprdx,0,'b'));
  adj_exposure = ((endprdx - begprdx) / 365);
  adj_amount = (amount / (end_date - start_date + 1)) * (endprdx - begprdx + 1);
  output;
  endprdx = min(end_date,intnx('year',endprdx,1,'e'));
end;
begprdx = max(start_date,intnx('year',end_date,0,'b'));
adj_exposure = round(endprdx - begprdx) / 365;
adj_amount = (amount / (end_date - start_date + 1)) * (endprdx - begprdx + 1);
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that data has to be presented in a data step with datalines; we can't write SAS programs for pictures.&lt;/P&gt;
&lt;P&gt;Please provide your example data in this form in the future, see it as a basic courtesy for those who are intended to help you.&lt;/P&gt;
&lt;P&gt;And you'll get answers quicker, because we do not have to waste time writing the data step ourselves.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 09:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728694#M28288</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-24T09:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert data from underwriting year basis to calendar year basis?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728741#M28289</link>
      <description>&lt;P&gt;Sincere apologies on the missing datalines from my code, I will take note on this. And thank you very much for your time and guidance, the code works fine now.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 13:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-data-from-underwriting-year-basis-to-calendar/m-p/728741#M28289</guid>
      <dc:creator>Ad_1993</dc:creator>
      <dc:date>2021-03-24T13:04:55Z</dc:date>
    </item>
  </channel>
</rss>

