<?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: PROC SQL AVG with calculated observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227898#M41108</link>
    <description>&lt;P&gt;Correct. But can I put a CASE statement in front of an AVG(observation) AS xxxx?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate an average for one observation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AVG(IF observation1 &amp;gt; 1 THEN observation2=observation2*2 ELSE observation2=observation2*3) AS new-observation;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want observation2 calulated to new value before it's averaged.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2015 18:56:16 GMT</pubDate>
    <dc:creator>G_I_Jeff</dc:creator>
    <dc:date>2015-09-30T18:56:16Z</dc:date>
    <item>
      <title>PROC SQL AVG with calculated observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227881#M41103</link>
      <description>&lt;P&gt;Trying to convert the following into one SQL statement, but can't wrap my head around the IF/THEN conditions. Is it possible to do in one SQL statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA TABLE1;&lt;/P&gt;
&lt;P&gt;SET TABLE2;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;IF OBS1 &amp;gt; 1 THEN&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;OBS3=((OBS4*.01)*(OBS5*215)) / ......;&lt;/P&gt;
&lt;P&gt;ELSE&lt;/P&gt;
&lt;P&gt;OBS3=((OBS4*.01)*(OBS5*315)) / ......;&lt;/P&gt;
&lt;P&gt;IF OBS1 &amp;gt; 100 THEN OBS1 = 100;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA=TABLE1;&lt;/P&gt;
&lt;P&gt;BY OBS1, OBS2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SUMMARY DATA=TABLE1;&lt;/P&gt;
&lt;P&gt;BY OBS1, OBS2;&lt;/P&gt;
&lt;P&gt;VAR OBS3;&lt;/P&gt;
&lt;P&gt;OUTPUT OUT=TABLE3;&lt;/P&gt;
&lt;P&gt;MEAN(OBS3)=AVGOBS;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how to obviously get the PROC SORT and PROC SUMMARY accomplished with SQL. Just need help with the IF/THEN in SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;/P&gt;
&lt;P&gt;CREATE TABLE3 AS&lt;/P&gt;
&lt;P&gt;SELECT OBS1, OBS2, AVG(OBS3) AS AVGOBS&lt;/P&gt;
&lt;P&gt;GROUP BY OBS1, OBS2;&lt;/P&gt;
&lt;P&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 18:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227881#M41103</guid>
      <dc:creator>G_I_Jeff</dc:creator>
      <dc:date>2015-09-30T18:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL AVG with calculated observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227891#M41104</link>
      <description>&lt;P&gt;It's going to be easier to provide a solution if you give an example of the data you have and what result you are looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 18:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227891#M41104</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-30T18:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL AVG with calculated observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227893#M41105</link>
      <description>For if then look up pl/sql decode() or case statements.</description>
      <pubDate>Wed, 30 Sep 2015 18:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227893#M41105</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-30T18:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL AVG with calculated observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227895#M41107</link>
      <description>IF/THEN convert most easily to CASE statements in SQL.</description>
      <pubDate>Wed, 30 Sep 2015 18:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227895#M41107</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-30T18:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL AVG with calculated observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227898#M41108</link>
      <description>&lt;P&gt;Correct. But can I put a CASE statement in front of an AVG(observation) AS xxxx?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate an average for one observation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AVG(IF observation1 &amp;gt; 1 THEN observation2=observation2*2 ELSE observation2=observation2*3) AS new-observation;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want observation2 calulated to new value before it's averaged.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 18:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227898#M41108</guid>
      <dc:creator>G_I_Jeff</dc:creator>
      <dc:date>2015-09-30T18:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL AVG with calculated observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227906#M41110</link>
      <description>&lt;P&gt;If I understand your question correctly then yes.&amp;nbsp; Put a comma in front and behind the case statement as if it were any other item you are selecting from the dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 19:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-AVG-with-calculated-observation/m-p/227906#M41110</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-30T19:14:24Z</dc:date>
    </item>
  </channel>
</rss>

