<?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: calculating average for derive variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722623#M224094</link>
    <description>The MEAN() function does that automatically so you don't need to do any manual checks. &lt;BR /&gt;If dealing with missing values, another function that's often used is COALESCE(), which takes the first non missing values from a list of variables. &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 01 Mar 2021 17:01:03 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-03-01T17:01:03Z</dc:date>
    <item>
      <title>calculating average for derive variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722531#M224053</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want to create a column (column_3) based on two other columns (column_1 and column_2).&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;if both column_1 and column_2 have a value then column_3 is the average of column_1 and column_2&lt;/LI&gt;
&lt;LI&gt;If the values for either column_1 or column_2 are missing (only one of them has a value) then column_3 is set equal to the non-missing value.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I know my code is wrong, but something like this&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;column_3=.;&lt;BR /&gt;if column_1 eq '.' and column_2&amp;gt;0 then column_3=column_2;&lt;BR /&gt;if column_2 eq '.' and column_1 &amp;gt;0 then column_3=column_1;&lt;BR /&gt;else if column_1&amp;gt;0 and column_2&amp;gt;0 then column_3 = (column_1+column_2)/2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 05:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722531#M224053</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-01T05:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: calculating average for derive variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722533#M224055</link>
      <description>&lt;P&gt;Assuming that the variables are numeric, you just compare with . not enclosed in quotes. But in your task, you don't have to use if at all. The function mean takes care of missing values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data havewant;
   input col1 col2;
   
   col3 = mean(col1, col2);
   
   datalines;   
5 .
. 7
4 6
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Mar 2021 06:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722533#M224055</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-03-01T06:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: calculating average for derive variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722617#M224091</link>
      <description>&lt;BR /&gt;Thank you, andreas! Great and easy solution!</description>
      <pubDate>Mon, 01 Mar 2021 16:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722617#M224091</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-01T16:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: calculating average for derive variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722623#M224094</link>
      <description>The MEAN() function does that automatically so you don't need to do any manual checks. &lt;BR /&gt;If dealing with missing values, another function that's often used is COALESCE(), which takes the first non missing values from a list of variables. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Mar 2021 17:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722623#M224094</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-01T17:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: calculating average for derive variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722625#M224095</link>
      <description>Thanks, Reeza. Good to know.</description>
      <pubDate>Mon, 01 Mar 2021 17:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculating-average-for-derive-variables/m-p/722625#M224095</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-01T17:03:53Z</dc:date>
    </item>
  </channel>
</rss>

