<?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: Credit Risk Model - Data Preparation using SAS Code in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371072#M24205</link>
    <description>&lt;P&gt;Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Jun 2017 22:27:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-06-27T22:27:44Z</dc:date>
    <item>
      <title>Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371014#M24196</link>
      <description>&lt;DIV&gt;Kindly note that I have a query which has 3 parts. I am in look for three different SAS code to deal with them.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1) For each observation date corresponding to a given acct_id, I am expected to check in the next 12 months including the given observation month&amp;nbsp;&amp;nbsp;for BQR , if it gets a value 9&amp;nbsp;then declare that acct_id at the given date to have a default_flag = 1 else 0&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2) As soon as an acct_id gets a default_flag = 1, I am expected to check further if in the next 60 months, BQR gets a value "W". If it gets a value "W", then I have to declare that acct_id at that given month to have write_off_flag = 1 else 0&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;3) I am expected to create variables BQR_1 to BQR_12 and populate values from the variable BQR for the next 12 months&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Please find the attached spreadsheet for sample query.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Also note:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1) The start date of each acct_id need not be the same&lt;/DIV&gt;&lt;DIV&gt;2) There is no record available for the acct_id as soon as it gets BQR status as "W"&lt;/DIV&gt;</description>
      <pubDate>Tue, 27 Jun 2017 18:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371014#M24196</guid>
      <dc:creator>Skb19121985</dc:creator>
      <dc:date>2017-06-27T18:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371021#M24200</link>
      <description>&lt;P&gt;So what is your question for us? This is your work, asking us to do it isn't a fair expectation and you haven't clearly illustrated what you need help with or what you've tried so far.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 18:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371021#M24200</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-27T18:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371031#M24204</link>
      <description>&lt;P&gt;Hi Reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for replying back.&lt;/P&gt;&lt;P&gt;Actually, I have 3 questions as listed out.&lt;/P&gt;&lt;P&gt;To reteriate , I wanted to flag an acct_id as default at a given observation date, if it is discovered to have defaulted with BQR=9 in the next 12 months.&lt;/P&gt;&lt;P&gt;Secondly, once, the defaulted acct_id at a given observation date is identified, I wanted to flag it as written-off if the BQR="W" in the next 12 months&lt;/P&gt;&lt;P&gt;Thirdly, I wanted to create variables BQR_1 to BQR_12 against each record (row)&amp;nbsp;and populate the values of BQR as observed in next 12 months from the date of observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope the query is clear by now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not able to think of the way to attempt at them so I have reached out directly on the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sandeep&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 18:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371031#M24204</guid>
      <dc:creator>Skb19121985</dc:creator>
      <dc:date>2017-06-27T18:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371072#M24205</link>
      <description>&lt;P&gt;Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 22:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371072#M24205</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-27T22:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371073#M24206</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146602"&gt;@Skb19121985&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for replying back.&lt;/P&gt;
&lt;P&gt;Actually, I have 3 questions as listed out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, once, the defaulted acct_id at a given observation date is identified, I wanted to flag it as written-off if the BQR="W" in the next 12 months&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Next 12 months" from when, the period that you may be looking at or 12 months from the date of default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope you provide examples of the input and output. I'm not going to look in the Excel for the reasons in my other response.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 22:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371073#M24206</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-27T22:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371094#M24207</link>
      <description>&lt;P&gt;Please find the SAS dataset code here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data credit_data ;&lt;BR /&gt;input acct_id $3. snapshot_date 6. BQR $8. ;&lt;BR /&gt;cards;&lt;BR /&gt;123&amp;nbsp;9001&amp;nbsp;4&lt;BR /&gt;123&amp;nbsp;9002&amp;nbsp;5&lt;BR /&gt;123&amp;nbsp;9003&amp;nbsp;6&lt;BR /&gt;123&amp;nbsp;9004&amp;nbsp;7&lt;BR /&gt;123&amp;nbsp;9005&amp;nbsp;8&lt;BR /&gt;123&amp;nbsp;9006&amp;nbsp;4&lt;BR /&gt;123&amp;nbsp;9007&amp;nbsp;4&lt;BR /&gt;123&amp;nbsp;9008&amp;nbsp;5&lt;BR /&gt;123&amp;nbsp;9009&amp;nbsp;6&lt;BR /&gt;123&amp;nbsp;9010&amp;nbsp;7&lt;BR /&gt;123&amp;nbsp;9011&amp;nbsp;8&lt;BR /&gt;123&amp;nbsp;9012&amp;nbsp;3&lt;BR /&gt;123&amp;nbsp;9101&amp;nbsp;1&lt;BR /&gt;123&amp;nbsp;9102&amp;nbsp;2&lt;BR /&gt;123&amp;nbsp;9103&amp;nbsp;3&lt;BR /&gt;123&amp;nbsp;9104&amp;nbsp;4&lt;BR /&gt;123&amp;nbsp;9105&amp;nbsp;5&lt;BR /&gt;123&amp;nbsp;9106&amp;nbsp;4&lt;BR /&gt;123&amp;nbsp;9107&amp;nbsp;5&lt;BR /&gt;123&amp;nbsp;9108&amp;nbsp;7&lt;BR /&gt;123&amp;nbsp;9109&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9110&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9111&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9112&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9201&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9202&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9203&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9204&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9205&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9206&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9207&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9208&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9209&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9210&amp;nbsp;9&lt;BR /&gt;123&amp;nbsp;9211&amp;nbsp;W&lt;BR /&gt;133&amp;nbsp;9101&amp;nbsp;1&lt;BR /&gt;133&amp;nbsp;9102&amp;nbsp;1&lt;BR /&gt;133&amp;nbsp;9103&amp;nbsp;1&lt;BR /&gt;133&amp;nbsp;9104&amp;nbsp;1&lt;BR /&gt;133&amp;nbsp;9105&amp;nbsp;2&lt;BR /&gt;133&amp;nbsp;9106&amp;nbsp;3&lt;BR /&gt;133&amp;nbsp;9107&amp;nbsp;4&lt;BR /&gt;133&amp;nbsp;9108&amp;nbsp;5&lt;BR /&gt;133&amp;nbsp;9109&amp;nbsp;4&lt;BR /&gt;133&amp;nbsp;9110&amp;nbsp;3&lt;BR /&gt;133&amp;nbsp;9111&amp;nbsp;5&lt;BR /&gt;133&amp;nbsp;9112&amp;nbsp;6&lt;BR /&gt;133&amp;nbsp;9201&amp;nbsp;7&lt;BR /&gt;133&amp;nbsp;9202&amp;nbsp;8&lt;BR /&gt;133&amp;nbsp;9203&amp;nbsp;7&lt;BR /&gt;133&amp;nbsp;9204&amp;nbsp;6&lt;BR /&gt;133&amp;nbsp;9205&amp;nbsp;5&lt;BR /&gt;133&amp;nbsp;9206&amp;nbsp;4&lt;BR /&gt;133&amp;nbsp;9207&amp;nbsp;5&lt;BR /&gt;133&amp;nbsp;9208&amp;nbsp;6&lt;BR /&gt;133&amp;nbsp;9209&amp;nbsp;7&lt;BR /&gt;133&amp;nbsp;9210&amp;nbsp;9&lt;BR /&gt;133&amp;nbsp;9211&amp;nbsp;9&lt;BR /&gt;133&amp;nbsp;9212&amp;nbsp;9&lt;BR /&gt;133&amp;nbsp;9301&amp;nbsp;9&lt;BR /&gt;133&amp;nbsp;9302&amp;nbsp;9&lt;BR /&gt;133&amp;nbsp;9303&amp;nbsp;9&lt;BR /&gt;133&amp;nbsp;9304&amp;nbsp;9&lt;BR /&gt;133&amp;nbsp;9305&amp;nbsp;8&lt;BR /&gt;133&amp;nbsp;9306&amp;nbsp;8&lt;BR /&gt;133&amp;nbsp;9307&amp;nbsp;8&lt;BR /&gt;133&amp;nbsp;9308&amp;nbsp;8&lt;BR /&gt;133&amp;nbsp;9309&amp;nbsp;8&lt;BR /&gt;133&amp;nbsp;9310&amp;nbsp;8&lt;BR /&gt;133&amp;nbsp;9311&amp;nbsp;9&lt;BR /&gt;133&amp;nbsp;9312&amp;nbsp;W&lt;BR /&gt;;&lt;BR /&gt;Run ;&lt;/P&gt;&lt;P&gt;Data credit_data (keep=snapshot_dte acct_id BQR BQR_1-BQR_12 default_flag write_off_flag) ;&lt;BR /&gt;set credit_data&amp;nbsp; ;&lt;BR /&gt;snapshot_dte = mdy(mod(snapshot_date,100),1,int(snapshot_date/100));&lt;BR /&gt;format snapshot_dte date9. ;&lt;BR /&gt;default_flag = . ;&lt;BR /&gt;write_off_flag = . ;&lt;BR /&gt;array BQRD(12) BQR_1-BQR_12 ;&lt;BR /&gt;Run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps in proceeding further.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 23:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371094#M24207</guid>
      <dc:creator>Skb19121985</dc:creator>
      <dc:date>2017-06-27T23:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371101#M24208</link>
      <description>&lt;P&gt;Solve Q3, then 1 and 2 become trivial.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Q3 -&amp;gt; LAG&amp;lt;n&amp;gt; function&lt;/P&gt;
&lt;P&gt;Q2/Q1 -&amp;gt; WHICHC function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested code below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data answers;
Set have;
By ID;

Array _bqr(*) $ bqr1-bqr12;

If first.id then count=1;
Else count + 1;

Bqr1 = lag(bqr);
Bqr2 = lag2(bqr2);
...
Bqr12 = lag12(bqr);

If count &amp;lt; 12 then do;
Do I=12 to count by -1;
_bqr(I) =.;
End;
End;

X=whichc('W', of _bqr(*));
Y=whichc('9', of _bqr(*));

Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 00:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371101#M24208</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-28T00:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371105#M24209</link>
      <description>&lt;P&gt;Hi Reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the reply, but this is not what I wanted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me clarify further. Let me focus on 1st query. I will take up remaining 2 queries in next thread one-by-one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Query1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create default_flag for row1 - acct_id = 123 BQR=4 and Snapshot_dte = 01JAN1990&lt;/P&gt;&lt;P&gt;This default flag is created in such a way that in next 12 month , that is SAS would read all records related to this acct_id from 01JAN1990 to 01DEC1990 and check if BQR=9 ever in this 12 month time and flag the variable default_flag = 1 , if found else 0 if not found against row1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly, when row2 - acct_id = 123 BQR=5 and Snapshot_dte = 01FEB1990 is read, the default flag is created in such a way that in next 12 month , that is SAS would read all records related to this acct_id from 01FEB1990 to 01JAN1991 and check if BQR=9 ever in this 12 month time and flag the variable default_flag = 1 , if found else 0 if not found against row2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This process is to be executed for each row forward looking into 12 months data and creating default_flag&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope the query is clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if it is not clear&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That means, the SAS code should be such that internally it loop for next 12 months per row and create default flag&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 00:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371105#M24209</guid>
      <dc:creator>Skb19121985</dc:creator>
      <dc:date>2017-06-28T00:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371108#M24210</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146602"&gt;@Skb19121985&lt;/a&gt;&amp;nbsp;That is how I understood your question. I guess you don't understand my response.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 01:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371108#M24210</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-28T01:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371117#M24211</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146602"&gt;@Skb19121985&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;3) I am expected to create variables BQR_1 to BQR_12 and populate values from the variable BQR for the next 12 months&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you create these variables ahead of time you don't have to loop for 1 as you seem to think. You can use them in the current row.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV&gt;1) For each observation date corresponding to a given acct_id, I am expected to check in the next 12 months including the given observation month&amp;nbsp;&amp;nbsp;for BQR , if it gets a value 9&amp;nbsp;then declare that acct_id at the given date to have a default_flag = 1 else 0&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;WHICHC searches a set of variables, BRQ1-BRQ12 to see if there's a value of 9.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 02:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371117#M24211</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-28T02:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371126#M24212</link>
      <description>&lt;P&gt;Hi Reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am almost near to what I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please have a look at the given SAS Code:&lt;/P&gt;&lt;P&gt;%macro zest();&lt;BR /&gt;Data answers;&lt;BR /&gt;Set credit_data;&lt;BR /&gt;By acct_id;&lt;BR /&gt;Array _bqr(*) $ BQR1-BQR12;&lt;BR /&gt;If first.acct_id then count=1;&lt;BR /&gt;Else count + 1;&lt;/P&gt;&lt;P&gt;%do i = 1 %to 12 ;&lt;BR /&gt;if eof&amp;amp;i. = 0 then&lt;BR /&gt;set credit_data (firstobs=&amp;amp;i. keep=BQR rename=(BQR=BQR&amp;amp;i.)) end=eof&amp;amp;i. ;&lt;BR /&gt;if last.acct_id then BQR&amp;amp;i. = "";&lt;BR /&gt;%end ;&lt;BR /&gt;write_off_flag=whichc('W', of _bqr(*));&lt;BR /&gt;default_flag=whichc('9', of _bqr(*));&lt;BR /&gt;count_max = max(count);&lt;BR /&gt;Run ;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%zest&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However you will notice that in the dataset that gets created, row number 25 to 34 , all the values below the diagonal W are picked up from the acct_id 133 data, when they should all be blank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly, for row number 61 to 71, all the values below the diagonal W are W, when they should all be blank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can u please rectify the code ?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 02:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/371126#M24212</guid>
      <dc:creator>Skb19121985</dc:creator>
      <dc:date>2017-06-28T02:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372343#M24270</link>
      <description>&lt;P&gt;I work with this type of data a lot and find that SQL is a pretty good way of handling it. I would start by deriving default and writeoff dates for each account and go from there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as 
  select  H1.acct_id
         ,min(H1.snapshot_date) as Start_Date format = date9.
         ,H2.Default_Date format = date9.
         ,H3.Writeoff_Date format = date9.
  from credit_data as H1

  left join
  (select acct_id 
         ,min(snapshot_date) as Default_Date
   from credit_data
   where BQR = '9'
   group by acct_id
  )  as H2
  on H1.acct_id = H2.acct_id

  left join
  (select acct_id 
         ,min(snapshot_date) as Writeoff_Date
   from credit_data
   where BQR = 'W'
   group by acct_id
  )  as H3
  on H1.acct_id = H3.acct_id

  group by H1.acct_id
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 01 Jul 2017 00:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372343#M24270</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-07-01T00:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372380#M24271</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;It is great to see that the default_date and write_off_date could be figured out for each acct_id through this code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that my query is a bit different.&lt;/P&gt;&lt;DIV&gt;1) For each observation date corresponding to a given acct_id (consider this as first date of observation and then look forward into next 12 months data), I am expected to check in the next 12 months including the given observation month&amp;nbsp;&amp;nbsp;for BQR , if it gets a value 9&amp;nbsp;then declare that acct_id at the given date to have a default_flag = 1 else 0 against that record&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2) As soon as an acct_id gets a default_flag = 1, I am expected to check further if in the next 60 months, BQR gets a value "W". If it gets a value "W", then I have to declare that acct_id at that given month to have write_off_flag = 1 else 0&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;3) I am also&amp;nbsp;expected to create forward looking variables BQR_1 to BQR_12 and populate values from the variable BQR for the next 12 months&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have tried to create a macro, however there is an issue.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;%macro zest();&lt;BR /&gt;Data answers;&lt;BR /&gt;Set credit_data;&lt;BR /&gt;By acct_id;&lt;BR /&gt;Array _bqr(*) $ BQR1-BQR12;&lt;BR /&gt;If first.acct_id then count=1;&lt;BR /&gt;Else count + 1;&lt;/P&gt;&lt;P&gt;%do i = 1 %to 12 ;&lt;BR /&gt;if eof&amp;amp;i. = 0 then&lt;BR /&gt;set credit_data (firstobs=&amp;amp;i. keep=BQR rename=(BQR=BQR&amp;amp;i.)) end=eof&amp;amp;i. ;&lt;BR /&gt;if last.acct_id then BQR&amp;amp;i. = "";&lt;BR /&gt;%end ;&lt;BR /&gt;write_off_flag=whichc('W', of _bqr(*));&lt;BR /&gt;default_flag=whichc('9', of _bqr(*));&lt;BR /&gt;count_max = max(count);&lt;BR /&gt;Run ;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%zest&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;Whereever the difference between the date of observance and the last date for each acct_id is less than 12 months, the code is trying to overstep and evaluate the data from the next acct_id.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I want this code to be suitably modified such that forward looking variables BQR1-BQR12 is correctly populated. To further clarify, if the difference between the date of observance (nth record)&amp;nbsp;&amp;amp; last date of acct_id is less than 12, say 11 then in this case BQR12 should be populated as BQR12 = . against nth record.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hope my query is clear.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If you run the above macro on the dataset SAS code given in the chain message, and check for the dataset named&amp;nbsp;"answers" and observe BQR1-BQR12 aginst each nth record in the dataset, you will get to know what is exactly happening.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sat, 01 Jul 2017 06:26:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372380#M24271</guid>
      <dc:creator>Skb19121985</dc:creator>
      <dc:date>2017-07-01T06:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372410#M24272</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146602"&gt;@Skb19121985&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Below some code which should return the result you're after.&lt;/P&gt;
&lt;P&gt;Looking into your Excel I don't understand why the write_off_flg gets only so late set to '1'. That's certainly later than 60 months ahead of the date where BQR gets a value of 'W'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date:anydtdte. acct_id:$16. BQR:$1.;
  format date date9.;
datalines;
1-Jan-90 123 4
1-Feb-90 123 5
1-Mar-90 123 6
1-Apr-90 123 7
1-May-90 123 8
1-Jun-90 123 4
1-Jul-90 123 4
1-Aug-90 123 5
1-Sep-90 123 6
1-Oct-90 123 7
1-Nov-90 123 8
1-Dec-90 123 3
1-Jan-91 123 1
1-Feb-91 123 2
1-Mar-91 123 3
1-Apr-91 123 4
1-May-91 123 5
1-Jun-91 123 4
1-Jul-91 123 5
1-Aug-91 123 7
1-Sep-91 123 9
1-Oct-91 123 9
1-Nov-91 123 9
1-Dec-91 123 9
1-Jan-92 123 9
1-Feb-92 123 9
1-Mar-92 123 9
1-Apr-92 123 9
1-May-92 123 9
1-Jun-92 123 9
1-Jul-92 123 9
1-Aug-92 123 9
1-Sep-92 123 9
1-Oct-92 123 9
1-Nov-92 123 W
1-Sep-90 133 1
1-Oct-90 133 1
1-Nov-90 133 1
1-Dec-90 133 1
1-Jan-91 133 2
1-Feb-91 133 3
1-Mar-91 133 4
1-Apr-91 133 5
1-May-91 133 4
1-Jun-91 133 3
1-Jul-91 133 5
1-Aug-91 133 6
1-Sep-91 133 7
1-Oct-91 133 8
1-Nov-91 133 7
1-Dec-91 133 6
1-Jan-92 133 5
1-Feb-92 133 4
1-Mar-92 133 5
1-Apr-92 133 6
1-May-92 133 7
1-Jun-92 133 9
1-Jul-92 133 9
1-Aug-92 133 9
1-Sep-92 133 9
1-Oct-92 133 9
1-Nov-92 133 9
1-Dec-92 133 9
1-Jan-93 133 8
1-Feb-93 133 8
1-Mar-93 133 8
1-Apr-93 133 8
1-May-93 133 8
1-Jun-93 133 8
1-Jul-93 133 9
1-Aug-93 133 W
;
run;

%let write_of_months=60;
data answers(drop=_:);
  set have;
  by acct_id date;

  retain default_flg '0' write_off_flag '0';

  if first.acct_id=1 then
    do;
      dcl hash h1(dataset:cats('have (where=(acct_id="',acct_id,'"))'),ordered:'y');
      h1.defineKey('acct_id','date');
      h1.defineData('bqr');
      h1.defineDone();
      declare hiter hh1 ('h1');

      default_flg='0';
      write_off_flag='0';
    end;
  
  /* populate bqr1 to bqr12 and default_flg */
  array _arr_bqr(*) $1 bqr1-bqr12;
  call missing(of _arr_bqr(*));
  _rc = hh1.setcur(key:acct_id,key:date);
  do _i=1 to 12 while (_rc = 0);
    _arr_bqr[_i]=bqr; 
    if bqr='9' then default_flg='1';
    _rc = hh1.next();
  end;

  /* populate write_off_flag */
  if write_off_flag='0' and default_flg='1' then
    do;
      _rc = hh1.setcur(key:acct_id,key:date);
      do _i=1 to &amp;amp;write_of_months while (_rc = 0);
        if bqr='W' then 
          do;
            write_off_flag='1';
            leave;
          end; 
        _rc = hh1.next();
      end;
    end;

  _rc = hh1.setcur(key:acct_id,key:date);

  if last.acct_id then h1.delete();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should you be dealing with large data volumes then tweaking for performance would be possible for the posted code - but it would complicate the syntax so it's only something I'd be doing if really necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jul 2017 12:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372410#M24272</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-07-01T12:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372431#M24274</link>
      <description>&lt;P&gt;Hi Patrick&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are incredible !&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;This is what is required.&lt;/P&gt;&lt;P&gt;Actually, to determine if an acct_id&amp;nbsp; that has already been declared defaulted (basis BQR getting "9" in 12 months performance window)&amp;nbsp;is written-off at a given observation date, BQR is observed for "W" in the next 12 months beginning the observation date with default_flag = 1in our practice instead of 60 as stated in my query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thinking of twigging the SAS statement such that the following is included in the program:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let write_of_months=12;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SAS code is working as required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, I will be using this SAS code on 300 GB dataset. Will it be time-taking ? If Yes, kindly help me with complicated syntax that you have stated in your reply, if possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, guide me with the study material that would help me become an expert SAS programmer just&amp;nbsp;like you. As of now, I am trying to get hold of key words that you have used in the SAS program that you have shared on my post &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jul 2017 17:12:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372431#M24274</guid>
      <dc:creator>Skb19121985</dc:creator>
      <dc:date>2017-07-01T17:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372509#M24275</link>
      <description>&lt;P&gt;IMO I don't see the need to create variables&amp;nbsp;BQR_1 to BQR_12 for the next 12 months when a simple default date and writeoff date will give you the same information but take up less disk space. If you are required to do this because of a data spec that's fine - just pointing out there are other simpler ways to approach this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jul 2017 07:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372509#M24275</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-07-02T07:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372514#M24277</link>
      <description>&lt;P&gt;Hi Sir&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that there are different ways of getting the required results without populating BQR1 to BQR12. The SAS code you presented is one such example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just wanted wanted to understand the SAS process to get all the 3 queries addressed in the same SAS program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SAS code that Patrick provided helped me also understand the SAS process through which I can populate some variables at time t by looking at the performance in next n months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jul 2017 08:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372514#M24277</guid>
      <dc:creator>Skb19121985</dc:creator>
      <dc:date>2017-07-02T08:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Credit Risk Model - Data Preparation using SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372625#M24280</link>
      <description>&lt;P&gt;Here is how you could add your flags into the one step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as 
  select  H1.acct_id
         ,min(H1.snapshot_date) as Start_Date format = date9.
         ,H2.Default_Date format = date9.
         ,case 
           when intck('MONTH', calculated Start_Date, H2.Default_Date, 'C') &amp;lt;= 12 then 1
           else 0
          end as Default_Flag
         ,H3.Writeoff_Date format = date9.
         ,case 
           when calculated Default_Flag = 1 and intck('MONTH', calculated Start_Date, Writeoff_Date, 'C') &amp;lt;= 60 then 1
           else 0
          end as Writeoff_Flag
  from credit_data as H1

  left join
  (select acct_id 
         ,min(snapshot_date) as Default_Date
   from credit_data
   where BQR = '9'
   group by acct_id
  )  as H2
  on H1.acct_id = H2.acct_id

  left join
  (select acct_id 
         ,min(snapshot_date) as Writeoff_Date
   from credit_data
   where BQR = 'W'
   group by acct_id
  )  as H3
  on H1.acct_id = H3.acct_id

  group by H1.acct_id
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Jul 2017 20:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Credit-Risk-Model-Data-Preparation-using-SAS-Code/m-p/372625#M24280</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-07-02T20:53:41Z</dc:date>
    </item>
  </channel>
</rss>

