<?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: Sum and multiplying with missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412723#M100940</link>
    <description>&lt;P&gt;You haven't told us what it means to ignore missing values.&amp;nbsp; For example, if only INTENS is missing, what should the result be?&amp;nbsp; If only WALK10 is missing, what should the result be?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The programming isn't that difficult.&amp;nbsp; But specifying the rules is.&lt;/P&gt;</description>
    <pubDate>Sun, 12 Nov 2017 20:29:29 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-11-12T20:29:29Z</dc:date>
    <item>
      <title>Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412692#M100936</link>
      <description>&lt;P&gt;Hi If I want to do the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want;
SET have;
score=(intens*walk10*walk20) + (intens*jog10*jog20) + (intens*run10*run20) + (intens*bike10*bike20) + (intens*swim10*swim20) + (intens*racquet10*racquet20) + (intens*vig_ex10*vig_ex20) + (intens*ball10*ball20) + (intens*stren10*stren20);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I don't get values for 'score'. I think it is because of the missing data. Do you know how I can handle the missing data here?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 15:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412692#M100936</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-11-12T15:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412697#M100937</link>
      <description>&lt;P&gt;1) What do you want to do with a mising value ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Do you want to ignore the multiplication (intent+xxx10*xxx20) for any xxx ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Your formule is equivalent to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intent * (walk10*walk20 + jog10*jog20 + run10*run20 ...)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;You can use arrays and the function sum to get what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
        array x10 walk10 jog10 run10 .... ;
        array x20 walk20 jog20 run20 .... ;
       score = 0;   /* initialize */
       do i=1 to dim(x10);
            score = sum(of score, x10(i) * x20(i));
       end;&lt;BR /&gt;       score = intens * score;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 15:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412697#M100937</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-12T15:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412701#M100938</link>
      <description>&lt;P&gt;Thank you, I want SAS to not take the missing value in to account. So it only calculates with the non-missing values.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;When I apply your syntax to my data, I only get 0 out of my score.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand what this means:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;score = 0;   /* initialize */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And do I need to have another 'do' sentence? Like this;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to dim(x20);&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Nov 2017 16:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412701#M100938</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-11-12T16:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412703#M100939</link>
      <description>&lt;P&gt;In my code I initialize the score with zero, then have a loop to calculate the sum of the multiplications.&lt;/P&gt;
&lt;P&gt;finally multiply the total sum (in the score variable) by intens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The statement:&amp;nbsp; &lt;STRONG&gt;do i=1 to dim(x10);&amp;nbsp;&lt;/STRONG&gt; - assumes that for each x10 member there is a x20 member so&lt;/P&gt;
&lt;P&gt;both arrays have same dimension.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 16:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412703#M100939</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-12T16:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412723#M100940</link>
      <description>&lt;P&gt;You haven't told us what it means to ignore missing values.&amp;nbsp; For example, if only INTENS is missing, what should the result be?&amp;nbsp; If only WALK10 is missing, what should the result be?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The programming isn't that difficult.&amp;nbsp; But specifying the rules is.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 20:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412723#M100940</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-12T20:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412823#M100984</link>
      <description>&lt;P&gt;Sorry, this was the first time I used arrays. I read about it and understand the programming part. But I don't get values yet for score..&amp;nbsp;Is it because there are a lot of missing values? In all the parts of the formula there could be missing values. And I want SAS to only calculate with the non-missing values.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 09:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412823#M100984</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-11-13T09:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412830#M100985</link>
      <description>&lt;P&gt;Run next code to count how many values are missing out of total values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
  set have  end=eof ;
        array x10 walk10 jog10 run10 .... ;
        array x20 walk20 jog20 run20 .... ;
        
       retain total  missvalue 0;
       do i=1 to dim(x10);
            total + 2;   /* two variables to check */
            if x10(i) = . then missvalue+1;
            if x20(i) = . then missvalue+1;
       end; 

       if eof then put total= missvalue=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Check message in log.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 10:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412830#M100985</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-13T10:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412831#M100986</link>
      <description>&lt;P&gt;Yes, I did that: total=2088 missvalue=1634. So a lot of missing values. But is there a way to do this datastep with only the non-missing values? Because some values in 'intens' variable are also missing. So;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;score=intens*score;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;will give a lot of zero's..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to deal with that? I tried this;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF intens&amp;gt;. THEN DO;
score=intens*score;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;But doesn't help..&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 10:35:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412831#M100986</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-11-13T10:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412834#M100987</link>
      <description>&lt;P&gt;You should remeber that any calculation with missing value will result into missing value,&lt;/P&gt;
&lt;P&gt;except when using some functions or procedures:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; let assign miss = .;&amp;nbsp; as missing value then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; any_X + miss = miss&amp;nbsp; &amp;nbsp;(same with subtraction)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; any_X * miss = miss&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using function (as I did in code proposed) SUM(OF ...) treats missing value as zero,&lt;/P&gt;
&lt;P&gt;then&amp;nbsp; &amp;nbsp;sum(of any_X , miss) = any_X.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case that INTENS is missing then you can skip those rows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have (where=(intens ne .));    /* WHERE condition added */
        array x10 walk10 jog10 run10 .... ;
        array x20 walk20 jog20 run20 .... ;
       score = 0;   /* initialize */
       do i=1 to dim(x10);
            score = sum(of score, x10(i) * x20(i));
       end;       
      score = intens * score;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 11:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412834#M100987</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-13T11:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and multiplying with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412869#M100999</link>
      <description>&lt;P&gt;Thanks for your help! I think I found the solution! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 12:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-multiplying-with-missing-values/m-p/412869#M100999</guid>
      <dc:creator>hovliza</dc:creator>
      <dc:date>2017-11-13T12:43:04Z</dc:date>
    </item>
  </channel>
</rss>

