<?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: When expanding data for modeling, there is an issue with overlapping dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875394#M345875</link>
    <description>&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;It seems like a lot of code, and I’m not exactly sure what it does, or why the table is missing an observation with a ‘Default’ .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt; Can you maybe take a step back and explain what your table should &lt;STRONG&gt;have (vs &lt;U&gt;not&lt;/U&gt; have)? &lt;/STRONG&gt;Start from scratch. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;Maybe it should look like &lt;FONT color="#008000"&gt;&lt;STRONG&gt;HAVE&lt;/STRONG&gt;&lt;/FONT&gt;, except:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;With a column for each ID’s &lt;STRONG&gt;&lt;EM&gt;earliest default date&lt;/EM&gt;&lt;/STRONG&gt;, if it exists, or&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;With a column for each ID’s &lt;STRONG&gt;&lt;EM&gt;most recent default date&lt;/EM&gt;&lt;/STRONG&gt;, if it exists.”&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;Add in additional requirements, if any.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2023 03:15:15 GMT</pubDate>
    <dc:creator>MelissaM</dc:creator>
    <dc:date>2023-05-12T03:15:15Z</dc:date>
    <item>
      <title>When expanding data for modeling, there is an issue with overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875323#M345856</link>
      <description>&lt;P&gt;Hello, I am trying to prepare an extrapolated modeling dataset, which is quite challenging because there are overlapping periods. I have written a query below, and I am close, but could you please help me reach the attached target table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA HAVE;
LENGTH ID 8 APP_DATE 8 RATING $ 10 DELINQUENCY 8 BALANCE 8 ;
INFILE DATALINES MISSOVER DLM=",";
INPUT ID APP_DATE RATING DELINQUENCY BALANCE;
FORMAT APP_DATE DATE9.;
DATALINES;
1,20027,BB+,0,10000
1,20119,BB,30,9000
1,20635,BB-,60,8000
1,20939,Default,91,5000
2,19023,BB-,30,7000
2,19509,BB,0,6000
2,20027,BB-,30,4000
2,20147,Default,91,3000
RUN;


DATA INTERMEDIATE;
SET HAVE;
FORMAT DATE_OF_DEFAULT DATE9.;
IF RATING = 'Default' THEN DATE_OF_DEFAULT=INTNX("month",APP_DATE,0,"E");
RUN;


PROC SORT DATA=INTERMEDIATE;
	BY ID DESCENDING DATE_OF_DEFAULT APP_DATE;
RUN;

DATA WANTED;
	SET INTERMEDIATE;
	BY ID DESCENDING DATE_OF_DEFAULT APP_DATE;
	RETAIN DATE_OF_DEFAULT_;
	FORMAT DATE_OF_DEFAULT_ DEFAULT_W12MNTH DEFAULT_W24MNTH COHORT_DATE DATE9.;
	IF NOT MISSING(DATE_OF_DEFAULT) THEN
		DATE_OF_DEFAULT_=DATE_OF_DEFAULT;
	ELSE DATE_OF_DEFAULT=DATE_OF_DEFAULT_;


	MONTH_DIFFERENCE=intck("MONTH", APP_DATE, DATE_OF_DEFAULT);
	DEFAULT_W12MNTH= INTNX("MONTH",DATE_OF_DEFAULT ,-12,'S');
	DEFAULT_W24MNTH= INTNX("MONTH",DATE_OF_DEFAULT ,-24,'S');

	IF MONTH_DIFFERENCE&amp;gt;0 THEN
		DO;
			DO I=0 TO MONTH_DIFFERENCE;
				COHORT_DATE= INTNX("MONTH",APP_DATE ,I,'E');

				IF COHORT_DATE &amp;gt; DEFAULT_W12MNTH THEN
					DEFAULT_FLG12MNTH=1;
				ELSE DEFAULT_FLG12MNTH=0;

				IF COHORT_DATE &amp;gt; DEFAULT_W24MNTH THEN
					DEFAULT_FLG24=1;
				ELSE DEFAULT_FLG24=0;
				OUTPUT;
			END;
		END;
	ELSE
		DO;
			COHORT_DATE=DATE_OF_DEFAULT;
			OUTPUT;
		END;
	DROP DATE_OF_DEFAULT_ I MONTH_DIFFERENCE DEFAULT_W12MNTH DEFAULT_W24MNTH;
RUN;

PROC SORT DATA=WANTED ;
	BY ID APP_DATE DATE_OF_DEFAULT ;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Desired.PNG" style="width: 418px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83892iF9982DA430A3B1C6/image-dimensions/418x287?v=v2" width="418" height="287" role="button" title="Desired.PNG" alt="Desired.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 18:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875323#M345856</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2023-05-11T18:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: When expanding data for modeling, there is an issue with overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875355#M345867</link>
      <description>&lt;P&gt;Please give us at least a hint of what you need help with. Which variable(s)? for which observations. And the rules needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Providing a picture is extremely hard to follow what is wrong without some description of where to look.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 21:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875355#M345867</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-11T21:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: When expanding data for modeling, there is an issue with overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875361#M345869</link>
      <description>&lt;P&gt;You're right, it's a bit complicated. Let me try to explain it in more detail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The overwhelming superiority should be towards the dates that match (or overlap) with the greater APP_DATE rating in descending order, with the aim of always keeping the most up-to-date information in the data. As you can see in my result view, the larger APP_DATE values are overpowering the records that overlap with them (for example, APP_DATE dated 31JAN2015 should not be displayed for the period from 31MAR2017, to 30JUN2016(Cause overlapping by APP_DATE 30JUN2016). Instead, APP_DATE from 30JUN2016, should be displayed)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Moreover, starting from the default moment, there should be 12 and 24-month Default_Flag variables for past periods&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 22:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875361#M345869</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2023-05-11T22:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: When expanding data for modeling, there is an issue with overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875363#M345870</link>
      <description>&lt;P&gt;I think if you run my code and compare my desired output, you will understand what I am trying to do(or what is the issue)&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 22:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875363#M345870</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2023-05-11T22:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: When expanding data for modeling, there is an issue with overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875394#M345875</link>
      <description>&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;It seems like a lot of code, and I’m not exactly sure what it does, or why the table is missing an observation with a ‘Default’ .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt; Can you maybe take a step back and explain what your table should &lt;STRONG&gt;have (vs &lt;U&gt;not&lt;/U&gt; have)? &lt;/STRONG&gt;Start from scratch. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;Maybe it should look like &lt;FONT color="#008000"&gt;&lt;STRONG&gt;HAVE&lt;/STRONG&gt;&lt;/FONT&gt;, except:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;With a column for each ID’s &lt;STRONG&gt;&lt;EM&gt;earliest default date&lt;/EM&gt;&lt;/STRONG&gt;, if it exists, or&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;With a column for each ID’s &lt;STRONG&gt;&lt;EM&gt;most recent default date&lt;/EM&gt;&lt;/STRONG&gt;, if it exists.”&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;FONT size="2"&gt;Add in additional requirements, if any.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 03:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-expanding-data-for-modeling-there-is-an-issue-with/m-p/875394#M345875</guid>
      <dc:creator>MelissaM</dc:creator>
      <dc:date>2023-05-12T03:15:15Z</dc:date>
    </item>
  </channel>
</rss>

