<?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- MEDIAN FUNCTION in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80930#M23325</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;Median is a a row-wise not an aggregate function in proc sql.&amp;nbsp; Take a look at:&lt;A class="jive-link-external-small" href="http://www.sascommunity.org/wiki/Fun_with_PROC_SQL_Summary_Functions" style="font-style: inherit; font-family: inherit; color: #0e66ba;"&gt;http://www.sascommunity.org/wiki/Fun_with_PROC_SQL_Summary_Functions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;If you need to use median values, calculate them with proc means or proc summary, and merge the results with your original data before doing your proc sql run.&amp;nbsp; However, do realize that with an even number of observations, it is quite possible that no record will contain the median value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 30 Sep 2012 14:05:23 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2012-09-30T14:05:23Z</dc:date>
    <item>
      <title>PROC SQL- MEDIAN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80929#M23324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to obtain the Median using the PROC SQL function (basically because I need the variables of that particular observation to show up in the output as well, which PROC MEANS doesn't do so).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have used the following code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE data2 AS SELECT*&lt;/P&gt;&lt;P&gt;FROM work.data1 GROUP BY DATE,R_PRICE&lt;/P&gt;&lt;P&gt;HAVING PRICE=MEDIAN(PRICE);&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I am trying to find the median given 2 conditions- DATE and R_PRICE)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the following error showed up,&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;WARNING: A GROUP BY clause has been transformed into an ORDER BY clause because neither the SELECT clause nor the optional HAVING clause of the associated table-expression referenced a summary function."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot guys. Appreciate it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Sep 2012 13:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80929#M23324</guid>
      <dc:creator>Benn</dc:creator>
      <dc:date>2012-09-30T13:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL- MEDIAN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80930#M23325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;Median is a a row-wise not an aggregate function in proc sql.&amp;nbsp; Take a look at:&lt;A class="jive-link-external-small" href="http://www.sascommunity.org/wiki/Fun_with_PROC_SQL_Summary_Functions" style="font-style: inherit; font-family: inherit; color: #0e66ba;"&gt;http://www.sascommunity.org/wiki/Fun_with_PROC_SQL_Summary_Functions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;If you need to use median values, calculate them with proc means or proc summary, and merge the results with your original data before doing your proc sql run.&amp;nbsp; However, do realize that with an even number of observations, it is quite possible that no record will contain the median value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Sep 2012 14:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80930#M23325</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-09-30T14:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL- MEDIAN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80931#M23326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arthur,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are spot on for my current problem. I have been trying to merge my result back all day long, but could not do so. Until just now I manually checked both datasets and realized that the median did not turn up. And immediately I saw your reply and confirmed my suspicion. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you happen to know a way about this? Eg. choosing the larger of the 2 middle numbers and so on?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank Arthur!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Sep 2012 14:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80931#M23326</guid>
      <dc:creator>Benn</dc:creator>
      <dc:date>2012-09-30T14:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL- MEDIAN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80932#M23327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure exactly what you want but, hopefully, the following example comes close:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=sashelp.class median nway;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var age;&lt;/P&gt;&lt;P&gt;&amp;nbsp; class sex;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out=medians (drop=_:) median=median_age;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=sashelp.class out=class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by sex;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge class medians;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by sex;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table test as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from need&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by sex&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having abs(age-median_age)=min(abs(age-median_age))&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Sep 2012 14:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80932#M23327</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-09-30T14:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL- MEDIAN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80933#M23328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arthur,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much for your help. Your code works like a charm and offered me some much needed progress after 3 days.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Oct 2012 15:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80933#M23328</guid>
      <dc:creator>Benn</dc:creator>
      <dc:date>2012-10-01T15:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL- MEDIAN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80934#M23329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;FYI beginning with SAS9.4 MEDIAN is also an aggregate function and can be used with proc sql, see sample below. See also doc here &lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/65065/HTML/default/viewer.htm#n123fsko39j44pn16zlt087e1m2h.htm" title="http://support.sas.com/documentation/cdl/en/sqlproc/65065/HTML/default/viewer.htm#n123fsko39j44pn16zlt087e1m2h.htm"&gt;SAS(R) 9.4 SQL Procedure User's Guide&lt;/A&gt;&lt;/P&gt;&lt;DIV style="font-family: Consolas; font-size: 14pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;sql&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;create&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; sample &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; make&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; , model&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; , invoice&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sashelp.cars&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; make&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;having&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; median(invoice) = invoice&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Apr 2014 14:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-MEDIAN-FUNCTION/m-p/80934#M23329</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2014-04-09T14:58:05Z</dc:date>
    </item>
  </channel>
</rss>

