<?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: array break until multiple condition met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496347#M131251</link>
    <description>&lt;P&gt;Do you want to check the last element of the array that is greater than 0 and populate it's ith-1 value of dt array in stp_dt? Just seeking some clarification?&lt;/P&gt;</description>
    <pubDate>Mon, 17 Sep 2018 18:02:11 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-09-17T18:02:11Z</dc:date>
    <item>
      <title>array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496344#M131248</link>
      <description>&lt;P&gt;I want to check "FC_2 -- FC_10" column and if FC_* &amp;gt;0 then corresponding&amp;nbsp; "dt_*-1" should populate.&lt;/P&gt;&lt;P&gt;I'm able to do the above task by create code below.&lt;/P&gt;&lt;P&gt;but there is one another constrain if FC_* become zero once again in same row then need to check FC_*&amp;gt;0 once again.&lt;/P&gt;&lt;P&gt;Please help !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ds1;&lt;BR /&gt;input fc_1-fc_10 (dt_1-dt_10) (:$2.);&lt;BR /&gt;datalines;&lt;BR /&gt;7 0 8 6 5 0 7 0 0 0 a e a e e a a e a e&lt;BR /&gt;7 0 3 10 3 2 10 8 4 7 b d b d d b b d b d&lt;BR /&gt;3 0 0 0 2 7 4 4 0 9 f g f g g f f g f g&lt;BR /&gt;3 0 0 4 3 10 1 9 4 7 a d a d d a a d a d&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ds2;&lt;BR /&gt;set ds1;&lt;/P&gt;&lt;P&gt;array fc[*] fc_1-fc_10;&lt;BR /&gt;array dt[*] dt_1-dt_10;&lt;/P&gt;&lt;P&gt;do i=2 to dim(fc);&lt;BR /&gt;if fc[i]&amp;gt;0 then do;&lt;BR /&gt;stp_dt=dt[i-1];&lt;BR /&gt;leave;&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*output should be like for stp_dt*/&lt;BR /&gt;for_first_row = dt_6&lt;BR /&gt;for_second_row = dt_2&lt;BR /&gt;for_thrid_row = dt_9&lt;BR /&gt;for_fourth_row = dt_3&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496344#M131248</guid>
      <dc:creator>atul_desh</dc:creator>
      <dc:date>2018-09-17T17:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496347#M131251</link>
      <description>&lt;P&gt;Do you want to check the last element of the array that is greater than 0 and populate it's ith-1 value of dt array in stp_dt? Just seeking some clarification?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496347#M131251</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-17T18:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496351#M131252</link>
      <description>Not exactly.... if Non-zero occurs and continue till end without getting zero then... its first occurrence -1......&lt;BR /&gt;&lt;BR /&gt;2) if its value become zero again and then again non-zero value then it should chk then newest greater than 0 values ith-1...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;a 0 b 2 c 4 d 0 ---&amp;gt; a&lt;BR /&gt;a 0 b 0 c 5 d 8 ---&amp;gt; b&lt;BR /&gt;a 0 b 3 c 0 d 9 ---&amp;gt; c</description>
      <pubDate>Mon, 17 Sep 2018 18:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496351#M131252</guid>
      <dc:creator>atul_desh</dc:creator>
      <dc:date>2018-09-17T18:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496354#M131254</link>
      <description>&lt;P&gt;still not sure i comprehend you, see if this is close?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data ds1;
input fc_1-fc_10 (dt_1-dt_10) (:$2.);
datalines;
7 0 8 6 5 0 7 0 0 0 a e a e e a a e a e
7 0 3 10 3 2 10 8 4 7 b d b d d b b d b d
3 0 0 0 2 7 4 4 0 9 f g f g g f f g f g
3 0 0 4 3 10 1 9 4 7 a d a d d a a d a d
;run;


data ds2;
set ds1;
array fc[*] fc_1-fc_10;
array dt[*] dt_1-dt_10;
do i=dim(fc) by -1 until(fc(i)&amp;gt;0);
if fc(i)&amp;gt;0 then stp_dt=dt[i-1];
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496354#M131254</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-17T18:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496365#M131261</link>
      <description>&lt;P&gt;Thanks for reply, but not working as expected &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ds1;&lt;BR /&gt;input fc_1-fc_10 (dt_1-dt_10) (:$2.);&lt;BR /&gt;datalines;&lt;BR /&gt;7 0 8 6 5 0 7 0 0 0 a b c d e f g h i j&lt;BR /&gt;7 0 3 10 3 2 10 8 4 7 a b c d e f g h i j&lt;BR /&gt;3 0 0 0 2 7 4 4 0 9 a b c d e f g h i j&lt;BR /&gt;3 0 0 4 3 10 1 9 4 7 a b c d e f g h i j&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data ds2;&lt;BR /&gt;set ds1;&lt;BR /&gt;array fc[*] fc_1-fc_10;&lt;BR /&gt;array dt[*] dt_1-dt_10;&lt;BR /&gt;do i=dim(fc) by -1 until(fc(i)&amp;gt;0);&lt;BR /&gt;if fc(i)&amp;gt;0 then stp_dt=dt[i-1];&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/**output**//&lt;/P&gt;&lt;P&gt;for_first_row = f;&lt;/P&gt;&lt;P&gt;for_second_row = b;&lt;/P&gt;&lt;P&gt;for_third_row = i;&lt;/P&gt;&lt;P&gt;for_fourth_row =b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496365#M131261</guid>
      <dc:creator>atul_desh</dc:creator>
      <dc:date>2018-09-17T18:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496366#M131262</link>
      <description>&lt;P&gt;Ok, i think i understand better this time. Let me tweak&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496366#M131262</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-17T18:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496371#M131265</link>
      <description>&lt;P&gt;If your fourth value should really be c rather than b, then the following would work:&lt;/P&gt;
&lt;PRE&gt;data ds1;
  input fc_1-fc_10 (dt_1-dt_10) (:$2.);
  datalines;
7 0 8 6 5 0 7 0 0 0 a b c d e f g h i j
7 0 3 10 3 2 10 8 4 7 a b c d e f g h i j
3 0 0 0 2 7 4 4 0 9 a b c d e f g h i j
3 0 0 4 3 10 1 9 4 7 a b c d e f g h i j
;

data ds2;
  set ds1;
  array fc[*] fc_1-fc_10;
  array dt[*] dt_1-dt_10;
  do i=dim(fc) by -1 until(fc(i-1) eq 0 and fc(i)&amp;gt;0);
    if fc(i-1) eq 0 and fc(i)&amp;gt;0 then stp_dt=dt[i-1];
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 19:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496371#M131265</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-09-17T19:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496380#M131268</link>
      <description>&lt;P&gt;elder &amp;amp; wiser but never old at master and hall of famer&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;, Thank you for the lead as it requires a tiny adjustment to meet OP's requirement as I plagiarize yours &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;PRE&gt;&lt;CODE class=" language-sas"&gt;
data ds1;
input fc_1-fc_10 (dt_1-dt_10) (:$2.);
datalines;
7 0 8 6 5 0 7 0 0 0 a b c d e f g h i j
7 0 3 10 3 2 10 8 4 7 a b c d e f g h i j
3 0 0 0 2 7 4 4 0 9 a b c d e f g h i j
3 0 0 4 3 10 1 9 4 7 a b c d e f g h i j
;run;

 
data ds2;
set ds1;
array fc[*] fc_1-fc_10;
array dt[*] dt_1-dt_10;
do i=dim(fc) by -1 until(fc(i-1) eq 0 and fc(i)&amp;gt;0);
 if fc(i-1) eq 0 and fc(i)&amp;gt;0 then
 do n=i-1 by -1 while(fc(n)=0);
 stp_dt=dt(n);
 end;
end;
drop i n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Sep 2018 19:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496380#M131268</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-17T19:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496399#M131279</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;: You're assuming that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/94664"&gt;@atul_desh&lt;/a&gt;&amp;nbsp;didn't just make an error regarding what was desired for the 4th test case. That may or may not be the case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is, your code as is won't correctly handle a case like:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;0 0 0 4 3 10 1 9 4 7 a b c d e f g h i j&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 21:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496399#M131279</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-09-17T21:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496403#M131281</link>
      <description>&lt;P&gt;I agree&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 21:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496403#M131281</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-17T21:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496407#M131285</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;: If your assumption is correct your code only needs one escape statement. e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds2;
  set ds1;
  array fc[*] fc_1-fc_10;
  array dt[*] dt_1-dt_10;
  do i=dim(fc) by -1 until(fc(i-1) eq 0 and fc(i)&amp;gt;0);
    if fc(i-1) eq 0 and fc(i)&amp;gt;0 then
     do n=i-1 by -1 while (fc(n) eq 0);
      stp_dt=dt(n);
      if n eq 1 then leave;
     end;
  end;
  drop i n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 21:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496407#M131285</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-09-17T21:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496412#M131289</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;, I am wondering is it possible to get away from linear search? my brain isn't functioning well today&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 21:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496412#M131289</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-17T21:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496413#M131290</link>
      <description>&lt;P&gt;Should be away to do it with a regular expression but, again, let's wait to see what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/94664"&gt;@atul_desh&lt;/a&gt;&amp;nbsp;really wants.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 21:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496413#M131290</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-09-17T21:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496443#M131303</link>
      <description>&lt;P&gt;Thank you all &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;below was working fine !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data ds2;&lt;BR /&gt;set ds1;&lt;BR /&gt;array fc[*] fc_1-fc_10;&lt;BR /&gt;array dt[*] dt_1-dt_10;&lt;BR /&gt;do i=dim(fc) by -1 until (fc(i)&amp;gt;0 and fc(i-1)=0) ;&lt;BR /&gt;if fc(i)&amp;gt;0 then stp_dt=dt[i-1];&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 02:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496443#M131303</guid>
      <dc:creator>atul_desh</dc:creator>
      <dc:date>2018-09-18T02:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496445#M131305</link>
      <description>&lt;P&gt;Thank you for the feedback. So&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;solutions have always been slick and this one too with no surprises. Please mark torontonian's answer and close the thread. Thank you for the interesting question though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 02:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496445#M131305</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-18T02:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: array break until multiple condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496560#M131360</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
  input fc_1-fc_10 (dt_1-dt_10) (:$2.);
  datalines;
7 0 8 6 5 0 7 0 0 0 a b c d e f g h i j
7 0 3 10 3 2 10 8 4 7 a b c d e f g h i j
3 0 0 0 2 7 4 4 0 9 a b c d e f g h i j
3 0 0 4 3 10 1 9 4 7 a b c d e f g h i j
;

data ds2;
  set ds1;
  array fc[*] fc_1-fc_10;
  array dt[*] dt_1-dt_10;
  do i=2 to dim(fc) ;
    if fc(i-1) eq 0 and fc(i)&amp;gt;0 then stp_dt=dt[i-1];
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Sep 2018 13:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-break-until-multiple-condition-met/m-p/496560#M131360</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-18T13:55:18Z</dc:date>
    </item>
  </channel>
</rss>

