<?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: How to get median using multiple criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/289079#M59686</link>
    <description>&lt;P&gt;Then use the SQL code. You can add a case statement with conditional logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If if you don't have SAS 9.4 then you'll have to either use proc means to calculate median, merge it in and execute conditional logic, or conditionally set values to missing ( volume&amp;lt;20) and use proc stdize.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Aug 2016 01:03:42 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-08-03T01:03:42Z</dc:date>
    <item>
      <title>How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288627#M59541</link>
      <description>&lt;P&gt;Hi, all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was hoping you could help me out on this query. I am able to do this in Excel using a combination of median and if function (somehow mimicking the averageif built-in function) but would like to have it translated in SAS due to the big amount of data I am working on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For illustration purposes, I have this sample dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Month &amp;nbsp; &amp;nbsp; &amp;nbsp;Day &amp;nbsp; &amp;nbsp; &amp;nbsp;Volume&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;27&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;56&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the dataset there are missing values represented by X and Y here. I need to fill out these missing values by getting the median of all the same &lt;STRONG&gt;month&lt;/STRONG&gt; and same &lt;STRONG&gt;day&amp;nbsp;&lt;/STRONG&gt;as that of the missing field. For example, in order to get X, i get the median of all those with month = 1 and day = 2. Similarly for Y, i get the median of all those with month = 1 and day= 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate your help! &amp;nbsp;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 15:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288627#M59541</guid>
      <dc:creator>Lady</dc:creator>
      <dc:date>2016-08-01T15:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288630#M59544</link>
      <description>&lt;P&gt;Look at proc STDIZE with the MISSING option to replace the missing values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The month and Hour are your BY Groups&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 15:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288630#M59544</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-01T15:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288692#M59552</link>
      <description>&lt;P&gt;Here's an example via code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile datalines truncover;
input Month      Day      Volume;
datalines;
1               1           20
1               2           
2               1           28
2               2           29
3               1           30
3               2           27
1               1           40
1               2           56
2               1           28
2               2           30
1               1           
1               2           30
;
run;
proc sort data=have;
by month day;
run;

proc stdize data=have out=want missing=median reponly;
by month day;
var volume;
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Aug 2016 19:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288692#M59552</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-01T19:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288694#M59553</link>
      <description>&lt;P&gt;And one more option, BUT this only works if you're on SAS 9.4+. In previous version, SAS SQL does not calculate the median correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want2 as
select *, median(volume) as med_volume, coalesce(volume, calculated med_volume) as Volume_Replaced
from have
group by month, day
order by month, day;
quit;

proc print data=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Aug 2016 19:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288694#M59553</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-01T19:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288892#M59627</link>
      <description>&lt;P&gt;Thank you, Reeza! This was very helpful.&amp;nbsp;&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>Tue, 02 Aug 2016 10:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288892#M59627</guid>
      <dc:creator>Lady</dc:creator>
      <dc:date>2016-08-02T10:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288952#M59639</link>
      <description>&lt;P&gt;by the way, what if instead of having missing values we have zero values instead? how do we get the median?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 15:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288952#M59639</guid>
      <dc:creator>Lady</dc:creator>
      <dc:date>2016-08-02T15:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288983#M59651</link>
      <description>&lt;P&gt;Then the solutions above wouldn't work. I would replace the 0 with missing and use the solution above.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 18:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/288983#M59651</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-02T18:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/289078#M59685</link>
      <description>&lt;P&gt;What if we need to add some criteria, say we need to have this logic:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if Volume &amp;lt; 20 then Adjusted Volume = median of the same month and day&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Month &amp;nbsp; &amp;nbsp; &amp;nbsp;Day &amp;nbsp; &amp;nbsp; &amp;nbsp;Volume &amp;nbsp; Adjusted Volume&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;27&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;56&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;10&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 00:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/289078#M59685</guid>
      <dc:creator>Lady</dc:creator>
      <dc:date>2016-08-03T00:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get median using multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/289079#M59686</link>
      <description>&lt;P&gt;Then use the SQL code. You can add a case statement with conditional logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If if you don't have SAS 9.4 then you'll have to either use proc means to calculate median, merge it in and execute conditional logic, or conditionally set values to missing ( volume&amp;lt;20) and use proc stdize.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 01:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-median-using-multiple-criteria/m-p/289079#M59686</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-03T01:03:42Z</dc:date>
    </item>
  </channel>
</rss>

