<?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 looping by rows with condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/looping-by-rows-with-condition/m-p/677513#M204368</link>
    <description>&lt;PRE&gt;data have;&lt;BR /&gt;input  var1 6.2  var2 6.2  var3 6.2;&lt;BR /&gt;datalines;&lt;BR /&gt;1400.00 165.55  839.57&lt;BR /&gt;0.00	0.00	106.42&lt;BR /&gt;1200.00	142.98	725.09&lt;BR /&gt;0.00	0.00	91.91&lt;BR /&gt;270.00	0.00	168.85&lt;BR /&gt;0.00	0.00	67.54&lt;BR /&gt;0.00	0.00	33.61&lt;BR /&gt;270.00	0.00	0.00&lt;BR /&gt;0.00	0.00	168.85&lt;BR /&gt;0.00	0.00	101.15&lt;BR /&gt;155.00	1.70	150.00&lt;BR /&gt;0.00	0.00	3.30&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Hello I want to verify if var1 &amp;lt; (var2+var3) by group (while I have 0.00) (1)&lt;BR /&gt;exemple:  1400.00 with 165.55 + 839.57 +106.42&lt;BR /&gt;          1200.00 with 142.98 + 725.09 + 91.91&lt;BR /&gt;          270.00 with 168.85 + 67.54 +33.61&lt;BR /&gt;want = new column 1 if i Have (1)&lt;BR /&gt;                  0 else&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Aug 2020 15:00:33 GMT</pubDate>
    <dc:creator>mazouz</dc:creator>
    <dc:date>2020-08-18T15:00:33Z</dc:date>
    <item>
      <title>looping by rows with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-by-rows-with-condition/m-p/677513#M204368</link>
      <description>&lt;PRE&gt;data have;&lt;BR /&gt;input  var1 6.2  var2 6.2  var3 6.2;&lt;BR /&gt;datalines;&lt;BR /&gt;1400.00 165.55  839.57&lt;BR /&gt;0.00	0.00	106.42&lt;BR /&gt;1200.00	142.98	725.09&lt;BR /&gt;0.00	0.00	91.91&lt;BR /&gt;270.00	0.00	168.85&lt;BR /&gt;0.00	0.00	67.54&lt;BR /&gt;0.00	0.00	33.61&lt;BR /&gt;270.00	0.00	0.00&lt;BR /&gt;0.00	0.00	168.85&lt;BR /&gt;0.00	0.00	101.15&lt;BR /&gt;155.00	1.70	150.00&lt;BR /&gt;0.00	0.00	3.30&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Hello I want to verify if var1 &amp;lt; (var2+var3) by group (while I have 0.00) (1)&lt;BR /&gt;exemple:  1400.00 with 165.55 + 839.57 +106.42&lt;BR /&gt;          1200.00 with 142.98 + 725.09 + 91.91&lt;BR /&gt;          270.00 with 168.85 + 67.54 +33.61&lt;BR /&gt;want = new column 1 if i Have (1)&lt;BR /&gt;                  0 else&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2020 15:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-by-rows-with-condition/m-p/677513#M204368</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-08-18T15:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: looping by rows with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-by-rows-with-condition/m-p/677516#M204370</link>
      <description>&lt;P&gt;You really need to add a variable to your data that indicates which "group" a set of records belongs to or explicitly define a rule that will let us know when a group begins. You don't provide that currently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise there really isn't a consistent way to see what a "group" may actually be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also need to show exactly how you expect your result to appear.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2020 15:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-by-rows-with-condition/m-p/677516#M204370</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-18T15:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: looping by rows with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-by-rows-with-condition/m-p/677526#M204373</link>
      <description>&lt;P&gt;This works, but there is not a single case in the "have" table that meets condition (1).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  var1   var2   var3 ;
datalines;
1400.00 165.55  839.57
0.00	0.00	106.42
1200.00	142.98	725.09
0.00	0.00	91.91
270.00	0.00	168.85
0.00	0.00	67.54
0.00	0.00	33.61
270.00	0.00	0.00
0.00	0.00	168.85
0.00	0.00	101.15
155.00	1.70	150.00
0.00	0.00	3.30
;
run;

data have1;
set have;
retain group 0;
if var1 ne 0 then group=group+1;
run;

data want;
set have1;
by group;
retain sum_var1 0 sum_var2_var3 0;

if first.group and last.group=0 then do;
sum_var1=var1; 
sum_var2_var3=sum(var2,var3);
end;

else if first.group=0 and last.group=0 then do;
sum_var1=sum(sum_var1,var1); 
sum_var2_var3=sum(sum_var2_var3,sum(var2,var3));
end;

else do;
sum_var1=sum(sum_var1,var1); 
sum_var2_var3=sum(sum_var2_var3,sum(var2,var3));
if sum_var1 &amp;lt; sum_var2_var3 then new=1;
else new=0;
end;
drop sum_var1 sum_var2_var3;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2020 20:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-by-rows-with-condition/m-p/677526#M204373</guid>
      <dc:creator>Angel_Larrion</dc:creator>
      <dc:date>2020-08-18T20:32:58Z</dc:date>
    </item>
  </channel>
</rss>

