<?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 first occurence and conditions within arrays in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48382#M13086</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art&lt;/P&gt;&lt;P&gt;you are right! &lt;/P&gt;&lt;P&gt;When the case of the Y is uncertain, whichC() provides no easy way (like find() function modifiers).&lt;/P&gt;&lt;P&gt;However, I'm surprised that these indicators have uncertain case. It is the kind of problem we would remove as the data are loaded (the $upcase. informat is simple). &lt;/P&gt;&lt;P&gt;I don't think we would recommend carrying information in the distinction between "y" and "Y". &lt;/P&gt;&lt;P&gt;When case is uncertain, I would recommend (for clarity rather than peformance), a data step view to upper-case them all. &lt;/P&gt;&lt;P&gt;data&amp;nbsp; I_view / view= I_view ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set I_have ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array upp dfm: ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do over upp ; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; upp = upcase( upp ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For performance, alternatives come to mind, like &lt;STRONG&gt;&lt;EM&gt;Def_month = find( cats( of dfm: ), 'y', 'i' ) ; &lt;/EM&gt;&lt;/STRONG&gt;as in&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; I_have ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; Def_month = find( cats( of dfm: ), &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 9pt;"&gt;'y'&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 9pt;"&gt;'i'&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; retain&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; dum &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; array&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; bal(*) dum bal: ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; not def_month &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; missing( def_balance ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; else&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; max( bal( def_month ), bal( def_month+&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; ) ) &amp;lt; &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; def_balance = disc_amt ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; def_balance = bal( def_month+&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; drop&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; dum ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I added DUM before the Balances in the array to remove exceptional handling when def_month=1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Nov 2011 11:22:58 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2011-11-18T11:22:58Z</dc:date>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48374#M13078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would be thankful if I could get help on:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data:-&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data I_have;input Dfm1$ Dfm2$ Dfm3$ Dfm4$ bal1 bal2 bal3 bal4 disc_amt;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp; 33&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp;&amp;nbsp; 40&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp; 44&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; 42&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&amp;nbsp;&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; 55&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp;&amp;nbsp; 99&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp;&amp;nbsp; 400&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Goal:- &lt;/STRONG&gt;Record the first occurence of the "Y" in a separate varaible called Def_month from the series &lt;/P&gt;&lt;P&gt;of the Variable/array called LDF,at the same point we take the Def_balance, shown in the code below. &lt;/P&gt;&lt;P&gt;To this extent I have completed the code. Now, if just before the first occurence and also at the first occurence of &lt;/P&gt;&lt;P&gt;"Y" the series of bal variable represented through Lbal remains less than or equal to 100 then Def_balance should equal &lt;/P&gt;&lt;P&gt;the variable disc_amt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;For example:-&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the first observation, first occurence of "Y" happens in Dfm1 therefore Def_month gets the value of 1 and since it this occurence come from first variable &lt;/P&gt;&lt;P&gt;so Def_balance=bal1 that is 200.&lt;/P&gt;&lt;P&gt;For the second observation occurence of "Y" happens in Dfm4 therefore Def_month gets the value of 4 and since it this occurence comes from fourth varialbe &lt;/P&gt;&lt;P&gt;so Def_balance=bal4 that is 4.But since we want extra condition to be fullfiled as discussed above the Def_balance then should be 50, value from disc_amt( needed output).This happens because 24 and 22 in Dfm3 and Dfm4 respectively have value less than 100; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data I_get;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;set I_have;&lt;/P&gt;&lt;P&gt;array LDF{*}$ dfm1-dfm4;&lt;/P&gt;&lt;P&gt;array Lbal{*} bal1-bal4;&lt;/P&gt;&lt;P&gt;do j=1 to dim(LDF);&lt;/P&gt;&lt;P&gt;if LDF(j) ="y" then do;&lt;/P&gt;&lt;P&gt;Def_month=j;&lt;/P&gt;&lt;P&gt;Def_balance=Lbal(j)&lt;/P&gt;&lt;P&gt;leave;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data I_wanna;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;input Dfm1$ Dfm2$ Dfm3$ Dfm4$ bal1 bal2 bal3 bal4 disc_amt Def_month Def_balance;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp; 33&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp;&amp;nbsp; 40&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&lt;/P&gt;&lt;P&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp; 44&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&lt;/P&gt;&lt;P&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; 42&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&amp;nbsp;&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&lt;/P&gt;&lt;P&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; 55&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&lt;/P&gt;&lt;P&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp;&amp;nbsp; 99&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp;&amp;nbsp; 400&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&lt;/P&gt;&lt;P&gt;;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 03:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48374#M13078</guid>
      <dc:creator>Swordfish</dc:creator>
      <dc:date>2011-11-16T03:22:58Z</dc:date>
    </item>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48375#M13079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You were close with your own code.&amp;nbsp; I only had to add one line and make a minor adjustment to another:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data I_want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set I_have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array LDF{*}$ dfm1-dfm4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array Lbal{*} bal1-bal4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do j=1 to dim(LDF);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if upcase(LDF(j)) ="Y" then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Def_month=j;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Def_balance=ifn(lbal(j) lt 100,disc_amt,Lbal(j));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leave;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 03:43:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48375#M13079</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-16T03:43:23Z</dc:date>
    </item>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48376#M13080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Art,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case we are not chekcing the lag of the first occurence of"Y". In the code we are only emphasizing at the point where first"Y" occured.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just make the matter clear. I add sixth observation in the data and show youhow the code impacts the results:-&lt;/P&gt;&lt;P class="im"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data I_have;input Dfm1$ Dfm2$ Dfm3$ Dfm4$ bal1 bal2 bal3 bal4 disc_amt;&lt;BR /&gt;Datalines;&lt;BR /&gt;y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp; 200&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp; 33&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp;&amp;nbsp; 40&amp;nbsp;&amp;nbsp; &lt;BR /&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp; 44&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp; &lt;BR /&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp; 42&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; 300&amp;nbsp;&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp; &lt;BR /&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp; 55&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&amp;nbsp;&amp;nbsp;&amp;nbsp; 300&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp; &lt;BR /&gt;N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp;&amp;nbsp; 99&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp; 400&amp;nbsp;&amp;nbsp;&amp;nbsp; 14 N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; N&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp; 44&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp; &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The above data is exactly the same as previous one but I have added only oneobservation. In the sixth observation you would see that the first occurence of"Y"&amp;nbsp; happens at variable Dfm4 and at that point variable bal4 is24( which is smaller than 100) but then to fullfil the second argument that lagof first occurence should also have balance lower than 100,it is only than wecan have Def_balance=disc_amt. if we observe the first lag, which in this casehappens to be bal3 which is not lower than 100 therefore the Def_balance shouldbe 24 not 50.But the code produces 50 for Def_balnce variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With lots of thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;BR /&gt;&lt;SPAN style="color: #888888;"&gt;&lt;BR /&gt;Tony&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 12:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48376#M13080</guid>
      <dc:creator>Swordfish</dc:creator>
      <dc:date>2011-11-16T12:28:09Z</dc:date>
    </item>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48377#M13081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure I follow what you are trying to accomplish, as your use of the term "lag" differs from its typical use in SAS which implies across records.&amp;nbsp; Does the following satisfy your extra condition?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data I_want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set I_have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array LDF{*}$ dfm1-dfm4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array Lbal{*} bal1-bal4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do j=1 to dim(LDF);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if upcase(LDF(j)) ="Y" then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Def_month=j;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use_disc_amt=disc_amt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if j gt 1 and lbal(j) lt 100 and lbal(j-1) ge 100&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then use_disc_amt=lbal(j);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Def_balance=ifn(lbal(j) lt 100,use_disc_amt,Lbal(j));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leave;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 13:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48377#M13081</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-16T13:28:15Z</dc:date>
    </item>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48378#M13082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;Data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; I_want (drop=j);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; I_have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; LDF{*}$ dfm1-dfm4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; Lbal{*} bal1-bal4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; j=&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;to&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; dim(LDF);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; upcase(LDF(j)) =&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 10pt;"&gt;"Y"&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Def_month=j;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; lbal(j) ge &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; def_balance=lbal(j);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;else&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; j&amp;gt;&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; and lbal(j-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;) ge &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp; def_balance=lbal(j);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; def_balance=disc_amt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;leave&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 14:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48378#M13082</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2011-11-16T14:15:37Z</dc:date>
    </item>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48379#M13083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Great....I am highly thankful to both Art and Linlin. Both codes were of great help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks once again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just a little change for the sake of fun otherwise above programs do not need any change&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data I_want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set I_have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array LDF{*}$ dfm1-dfm4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array Lbal{*} bal1-bal4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do j=1 to dim(LDF);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if upcase(LDF(j)) ="Y" then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Def_month=j;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use_disc_amt=disc_amt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if j gt 1 and lbal(j) lt 100 and lbal(j-1) ge 100&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then use_disc_amt=lbal(j);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Def_balance=ifn(lbal(j) lt 100,use_disc_amt,Lbal(j));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leave;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 15:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48379#M13083</guid>
      <dc:creator>Swordfish</dc:creator>
      <dc:date>2011-11-16T15:34:47Z</dc:date>
    </item>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48380#M13084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Surprised no one offered the function WHICHC()&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 15:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48380#M13084</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-11-16T15:41:08Z</dc:date>
    </item>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48381#M13085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Peter,&amp;nbsp; I agree that whichc would have simplified the code, but I couldn't figure out how to use it and simultaneously upcase the variables being checked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 16:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48381#M13085</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-16T16:22:54Z</dc:date>
    </item>
    <item>
      <title>first occurence and conditions within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48382#M13086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art&lt;/P&gt;&lt;P&gt;you are right! &lt;/P&gt;&lt;P&gt;When the case of the Y is uncertain, whichC() provides no easy way (like find() function modifiers).&lt;/P&gt;&lt;P&gt;However, I'm surprised that these indicators have uncertain case. It is the kind of problem we would remove as the data are loaded (the $upcase. informat is simple). &lt;/P&gt;&lt;P&gt;I don't think we would recommend carrying information in the distinction between "y" and "Y". &lt;/P&gt;&lt;P&gt;When case is uncertain, I would recommend (for clarity rather than peformance), a data step view to upper-case them all. &lt;/P&gt;&lt;P&gt;data&amp;nbsp; I_view / view= I_view ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set I_have ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array upp dfm: ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do over upp ; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; upp = upcase( upp ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For performance, alternatives come to mind, like &lt;STRONG&gt;&lt;EM&gt;Def_month = find( cats( of dfm: ), 'y', 'i' ) ; &lt;/EM&gt;&lt;/STRONG&gt;as in&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; I_have ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; Def_month = find( cats( of dfm: ), &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 9pt;"&gt;'y'&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 9pt;"&gt;'i'&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; retain&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; dum &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; array&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; bal(*) dum bal: ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; not def_month &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; missing( def_balance ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; else&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; max( bal( def_month ), bal( def_month+&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; ) ) &amp;lt; &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; def_balance = disc_amt ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; def_balance = bal( def_month+&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; drop&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; dum ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 9pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I added DUM before the Balances in the array to remove exceptional handling when def_month=1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Nov 2011 11:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/first-occurence-and-conditions-within-arrays/m-p/48382#M13086</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-11-18T11:22:58Z</dc:date>
    </item>
  </channel>
</rss>

