<?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 Sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616705#M180581</link>
    <description>&lt;P&gt;Please correct me if I am wrong:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Scenario:&lt;/P&gt;
&lt;P&gt;1. Create a variable, &lt;STRONG&gt;Bonus&lt;/STRONG&gt;, that is &lt;STRONG&gt;5%&lt;/STRONG&gt; of Income. If the Bonus is over $7000,&amp;nbsp; create the &lt;STRONG&gt;variable Total&lt;/STRONG&gt; that &lt;STRONG&gt;sums Bonus and Income&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2. Only output observations with &lt;STRONG&gt;Bonus greater than $7000&lt;/STRONG&gt; to the New dataset,&lt;STRONG&gt; BonusOver7K&lt;/STRONG&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; there should be &lt;STRONG&gt;no missing value&lt;/STRONG&gt; for the&lt;STRONG&gt; Bonus variable&lt;/STRONG&gt; in the data set.&lt;/P&gt;
&lt;P&gt;3.what is the value of the variable Total for observation 114?&lt;/P&gt;
&lt;P&gt;4. what is the&lt;STRONG&gt; grand total&lt;/STRONG&gt; of the &lt;STRONG&gt;variable Total&lt;/STRONG&gt; for the entire data set?*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.BonusOver7K;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Souj.input24;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Bonus=Income*&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0.5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Bonus ne &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Bonus&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7000&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then Total=sum(Bouns,Income);/* I think,#1*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Bonus&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7000&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BonusOver7K;/* I think, #2*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;print&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=BonusOver7K;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;sum&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Total; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* I think, #4 */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 11 Jan 2020 17:52:29 GMT</pubDate>
    <dc:creator>souji</dc:creator>
    <dc:date>2020-01-11T17:52:29Z</dc:date>
    <item>
      <title>Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616705#M180581</link>
      <description>&lt;P&gt;Please correct me if I am wrong:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Scenario:&lt;/P&gt;
&lt;P&gt;1. Create a variable, &lt;STRONG&gt;Bonus&lt;/STRONG&gt;, that is &lt;STRONG&gt;5%&lt;/STRONG&gt; of Income. If the Bonus is over $7000,&amp;nbsp; create the &lt;STRONG&gt;variable Total&lt;/STRONG&gt; that &lt;STRONG&gt;sums Bonus and Income&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2. Only output observations with &lt;STRONG&gt;Bonus greater than $7000&lt;/STRONG&gt; to the New dataset,&lt;STRONG&gt; BonusOver7K&lt;/STRONG&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; there should be &lt;STRONG&gt;no missing value&lt;/STRONG&gt; for the&lt;STRONG&gt; Bonus variable&lt;/STRONG&gt; in the data set.&lt;/P&gt;
&lt;P&gt;3.what is the value of the variable Total for observation 114?&lt;/P&gt;
&lt;P&gt;4. what is the&lt;STRONG&gt; grand total&lt;/STRONG&gt; of the &lt;STRONG&gt;variable Total&lt;/STRONG&gt; for the entire data set?*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.BonusOver7K;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Souj.input24;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Bonus=Income*&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0.5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Bonus ne &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Bonus&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7000&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then Total=sum(Bouns,Income);/* I think,#1*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Bonus&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7000&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BonusOver7K;/* I think, #2*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;print&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=BonusOver7K;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;sum&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Total; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* I think, #4 */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 17:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616705#M180581</guid>
      <dc:creator>souji</dc:creator>
      <dc:date>2020-01-11T17:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616711#M180585</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301371"&gt;@souji&lt;/a&gt;&lt;BR /&gt;Just a little mistake:&lt;BR /&gt;you should multiply by 0.05 to have 5% of the bonus.&lt;BR /&gt;You can optimize your code by using ‘do’ ‘end’:&lt;BR /&gt;&lt;BR /&gt;if Bonus&amp;gt;7000  then do;&lt;BR /&gt;Total=sum(Bouns,Income);/* I think,#1*/&lt;BR /&gt; output BonusOver7K;/* I think, #2*/&lt;BR /&gt;End;&lt;BR /&gt;run;</description>
      <pubDate>Sat, 11 Jan 2020 18:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616711#M180585</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-11T18:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616713#M180586</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;Please review your information about WHERE statements. I would expect that you are getting an ERROR message in your code something like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" color="#FF0000"&gt;ERROR: Variable Bonus is not on file SOUJ.INPUT24&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Because a WHERE statement can ONLY be used if the variable(s) in the WHERE already exist in the INPUT dataset (in this case SOUJ.INPUT24). And since you are creating BONUS, my assumption is that BONUS does not exist.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Since we do not know what variables you're starting with in SOUJ.INPUT24, it also might be that you DO have BONUS in that input data.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;You also have a TYPO here:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;if Bonus&amp;gt;7000 then Total=sum(&lt;FONT color="#FF0000"&gt;Bouns&lt;/FONT&gt;,Income);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So that is also going to be an issue because I think you meant to create TOTAL by summing BONUS and INCOME, not BO&lt;U&gt;&lt;FONT color="#FF0000"&gt;UN&lt;/FONT&gt;&lt;/U&gt;S and INCOME.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Remember that if you want to subset based on a variable (or column) you are creating in a program, then you can subset using a syntax construct called a "subsetting IF". Since you did not post any data, this program uses just 6 observations that test all your conditions. Generated values for BONUS fall above 7K and under 7K and one value is missing:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="use_subsetting_if.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35276i60B256BA73A2C425/image-size/large?v=v2&amp;amp;px=999" role="button" title="use_subsetting_if.png" alt="use_subsetting_if.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The subsetting IF will act as a "gate" and if an observation fails the test, processing will stop. That means for any observations where calculated Bonus is missing or under 7K, the observation will never get to the creation of TOTAL or the implicit output at the end of the DATA step program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2020 18:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616713#M180586</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-01-12T18:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616714#M180587</link>
      <description>Good catch about the diff between 5% and 50%!&lt;BR /&gt;Cynthia</description>
      <pubDate>Sat, 11 Jan 2020 18:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616714#M180587</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-01-11T18:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616716#M180588</link>
      <description>&lt;P&gt;Thank you very much for both of you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for correcting me ... I am still learning&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 19:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum/m-p/616716#M180588</guid>
      <dc:creator>souji</dc:creator>
      <dc:date>2020-01-11T19:28:02Z</dc:date>
    </item>
  </channel>
</rss>

