<?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 SumIF in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653734#M196350</link>
    <description>I'm trying to figure out the way to use 'sumif' in SAS to create the target variable (Total) in one single data step but I'm unable to accomplish it. Appreciate if someone of you help me.&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;I've the data&amp;amp;nbsp;(INPUT)&amp;amp;nbsp;as follows.&lt;BR /&gt;&lt;BR /&gt;Now I want to create the target variable 'Total' using the similar&amp;amp;nbsp;formula as below. I've got the requirement using SUMIF function from excel and when I simplify it, I end with the calculation as shown below. I knew that we don't have SUMIF in SAS but I was wondering what will be the equal to it in SAS and also not sure how to achive the this calculation in one data step.&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;Final values of 'Total' should be,&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;825.666&lt;BR /&gt;971.823&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;&amp;amp;nbsp;</description>
    <pubDate>Sun, 07 Jun 2020 14:37:32 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2020-06-07T14:37:32Z</dc:date>
    <item>
      <title>SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653734#M196350</link>
      <description>I'm trying to figure out the way to use 'sumif' in SAS to create the target variable (Total) in one single data step but I'm unable to accomplish it. Appreciate if someone of you help me.&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;I've the data&amp;amp;nbsp;(INPUT)&amp;amp;nbsp;as follows.&lt;BR /&gt;&lt;BR /&gt;Now I want to create the target variable 'Total' using the similar&amp;amp;nbsp;formula as below. I've got the requirement using SUMIF function from excel and when I simplify it, I end with the calculation as shown below. I knew that we don't have SUMIF in SAS but I was wondering what will be the equal to it in SAS and also not sure how to achive the this calculation in one data step.&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;Final values of 'Total' should be,&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;825.666&lt;BR /&gt;971.823&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;&amp;amp;nbsp;</description>
      <pubDate>Sun, 07 Jun 2020 14:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653734#M196350</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-07T14:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653737#M196353</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

/** I want to add a and c only if b &amp;gt; 0 **/

a=1;

b=2;

c=3;

sum=(a+c)*(b&amp;gt;0);

put sum=;

a=1;

b=-1;

c=3;

sum=(a+c)*(b&amp;gt;0);

put sum=;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 17:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653737#M196353</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-05T17:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653739#M196354</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;are you looking for such functionality like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x y;
cards;
1 10
5 13
3 12
4 10
2 11
;
run;

data want;
  set have end = EOF;
  partial_sum + ifn(y&amp;gt;10, x, 0); /* agregate for all rows if condition is satisfy  */

  if EOF; /* at the end of dataset */
  sum_square = partial_sum * partial_sum; /* generate final value */
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 17:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653739#M196354</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-05T17:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653740#M196355</link>
      <description>&lt;P&gt;How about instead of providing "code" that has little bearing on how SAS works show an actual formulae given the shown data.&lt;/P&gt;
&lt;P&gt;Since you do not tell us which column should be A or B or what ever, then the Excel formula is even more problematic. I would guess that your formula references more cells that you provided in the "example" since I see a $D, unless you actually intend to calculate something using the value of and ID variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not seeing any value to compare the cells to so am questioning the use of SUMIF at all. It looks like SUM would be the function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 17:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653740#M196355</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-05T17:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653743#M196357</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;Actual formula&amp;nbsp;to derive the target variable (Total)&amp;nbsp;is, shown below. Is there a way that you can help me with the sample data as I provided in the Initial post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;=SUMIF(INPUT!$A:$A;A2;INPUT!$G:$G)*SUMIF(INPUT!$A:$A;A2;INPUT!$H:$H)/SQRT(SUMIF(INPUT!$A:$A;A2;INPUT!$G:$G)^2+SUMIF(INPUT!$A:$A;A2;INPUT!$I:$I)^2+SUMIF(INPUT!$A:$A;A2;INPUT!$G:$G)*SUMIF(INPUT!$A:$A;A2;INPUT!$I:$I))&lt;/PRE&gt;
&lt;P&gt;A refers to the field 'ID'&lt;/P&gt;
&lt;P&gt;G refers to the field 'HNSLT_GR'&lt;/P&gt;
&lt;P&gt;H refers to the field 'H_GR'&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;refers to the field 'HSLT_GR'&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 17:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653743#M196357</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-05T17:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653745#M196359</link>
      <description>An picture of two lines of data without cell references is not 'sample data' we can work with please post data as text.</description>
      <pubDate>Fri, 05 Jun 2020 17:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653745#M196359</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-05T17:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653746#M196360</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;Actual formula&amp;nbsp;to derive the target variable (Total)&amp;nbsp;is, shown below. Is there a way that you can help me with the sample data as I provided in the Initial post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;=SUMIF(INPUT!$A:$A;A2;INPUT!$G:$G)*SUMIF(INPUT!$A:$A;A2;INPUT!$H:$H)/SQRT(SUMIF(INPUT!$A:$A;A2;INPUT!$G:$G)^2+SUMIF(INPUT!$A:$A;A2;INPUT!$I:$I)^2+SUMIF(INPUT!$A:$A;A2;INPUT!$G:$G)*SUMIF(INPUT!$A:$A;A2;INPUT!$I:$I))&lt;/PRE&gt;
&lt;P&gt;A refers to the field 'ID'&lt;/P&gt;
&lt;P&gt;G refers to the field 'HNSLT_GR'&lt;/P&gt;
&lt;P&gt;H refers to the field 'H_GR'&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;refers to the field 'HSLT_GR'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's a start. Now, what exactly are we "summing"? I don't speak Excel that well and with only two rows of data you should be able to write out the equation such as&amp;nbsp;&amp;nbsp; (123 + 456) / (456)&amp;nbsp; or what ever using the values you show.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 17:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653746#M196360</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-05T17:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653748#M196362</link>
      <description>&lt;P&gt;Why don't you formulate your issue in plain language, like "when condition a is met, do calculation b, otherwise do calculation c"?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 17:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653748#M196362</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-05T17:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653749#M196363</link>
      <description>&lt;P&gt;You might as well go ahead and use&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;sum=sum(a,c)*(b&amp;gt;0);&lt;/LI-CODE&gt;
&lt;P&gt;The value of sum will be 0 when b is less than or equal to zero, which includes missing. Does that match your need?&lt;/P&gt;
&lt;P&gt;If you are dividing anything by that sum you should check that the total is not zero to avoid the "divide by zero" errors.&lt;/P&gt;
&lt;P&gt;Since it appears your "overall formula" did not involve counts of things then I suspect having the occasional 0 isn't going to be a problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or use&lt;/P&gt;
&lt;P&gt;if b&amp;gt; 0 then sum= sum(a,c);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You likely want to consider what to do if one of A or C is missing. In SAS A+C is missing if either of the two variables has a missing value. If in that case you want the value of what either variable may have you should use the SUM function, which I think is going to be more like the Excel result.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 18:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653749#M196363</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-05T18:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653859#M196393</link>
      <description>&lt;P&gt;If I simplify the Excel formula, then I get this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;=(sum of G)*(sum of H)/SQRT((sum of G)^2+(sum of I)^2+(sum of G)*(sum of I))&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jun 2020 03:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653859#M196393</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-06T03:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653860#M196394</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;Now I've simplified the excel formula and updated the initial post. I would like to know how to derive the target variables in one data step.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jun 2020 03:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653860#M196394</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-06T03:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653865#M196397</link>
      <description>&lt;P&gt;What do you mean by "sum of"? Is "sum of G" a vertical summation of column G over all observations?&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jun 2020 04:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653865#M196397</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-06T04:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653867#M196398</link>
      <description>Yes, have to sum all values of the respective fields.</description>
      <pubDate>Sat, 06 Jun 2020 05:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653867#M196398</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-06T05:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: SumIF in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653872#M196401</link>
      <description>&lt;P&gt;So it would be this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select
  sum(G) * sum(H) / sqrt(sum(G) ** 2 + sum(I) ** 2 + sum(G) * sum(I))
  as wanted
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Jun 2020 07:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SumIF-in-SAS/m-p/653872#M196401</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-06T07:02:02Z</dc:date>
    </item>
  </channel>
</rss>

