<?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: Median values from from repeated sampling in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393234#M94684</link>
    <description>Yep- that's exactly what I was looking for. Thanks a lot!&lt;BR /&gt;My sql skills are really lacking so I really appreciate it</description>
    <pubDate>Tue, 05 Sep 2017 14:28:30 GMT</pubDate>
    <dc:creator>LMan19</dc:creator>
    <dc:date>2017-09-05T14:28:30Z</dc:date>
    <item>
      <title>Median values from from repeated sampling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393226#M94681</link>
      <description>&lt;DIV class="post-text"&gt;&lt;P&gt;I have a large dataset that has includes values of a chemical concentration, the date of testing, the site of testing, and a lot of other variable not immediately relevant to this question. Some of these values are from samples taken on the same day; sometimes up to ~100 tests/day. So, for example, you end up with a data set that looks something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SiteID SampleDate Concentration
1      1/1/2000               1
1      1/1/2000               2
1      1/1/2000               3
1      1/1/2001               1
1      1/1/2002               1
1      1/1/2003               1
2      1/1/2000               1
2      1/1/2000               2   
2      1/1/2001               1
2      1/1/2001               2
3      1/1/2000               1
3      1/1/2002               1
4      1/1/2001               1
4      1/1/2002               1
4      1/1/2003               1
4      1/1/2003               2
4      1/1/2004               1
5      1/1/2003               1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In subsequent analyses I just need the median value from each day, so I am trying to 1) determine the median concentration per site per day and 2) create a new output data set that uses the calculated median value rather than the original concentration and displays the number of samples taken on the same date; using the example data above, something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SiteID SampleDate      Med_Conc  SampleN
1      1/1/2000               2        3
1      1/1/2001               1        1
1      1/1/2002               1        1
1      1/1/2003               1        1
2      1/1/2000             1.5        2
2      1/1/2001             1.5        2
3      1/1/2000               1        1
3      1/1/2002               1        1
4      1/1/2001               1        1
4      1/1/2002               1        1
4      1/1/2003             1.5        2
4      1/1/2004               1        1
5      1/1/2003               1        1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm at a loss on how to do this, so any help would be greatly appreciated.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Sep 2017 14:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393226#M94681</guid>
      <dc:creator>LMan19</dc:creator>
      <dc:date>2017-09-05T14:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Median values from from repeated sampling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393231#M94683</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input SiteID$ SampleDate:ddmmyy10. Concentration;
format SampleDate ddmmyy10.;
datalines;
1      1/1/2000               1
1      1/1/2000               2
1      1/1/2000               3
1      1/1/2001               1
1      1/1/2002               1
1      1/1/2003               1
2      1/1/2000               1
2      1/1/2000               2   
2      1/1/2001               1
2      1/1/2001               2
3      1/1/2000               1
3      1/1/2002               1
4      1/1/2001               1
4      1/1/2002               1
4      1/1/2003               1
4      1/1/2003               2
4      1/1/2004               1
5      1/1/2003               1
;

proc sql;
   create table want as
   select SiteID
         ,SampleDate
         ,median(Concentration) as Med_Conc
         ,count(Concentration) as SampleN
   from have
   group by SiteID, SampleDate;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Sep 2017 14:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393231#M94683</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-09-05T14:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Median values from from repeated sampling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393234#M94684</link>
      <description>Yep- that's exactly what I was looking for. Thanks a lot!&lt;BR /&gt;My sql skills are really lacking so I really appreciate it</description>
      <pubDate>Tue, 05 Sep 2017 14:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393234#M94684</guid>
      <dc:creator>LMan19</dc:creator>
      <dc:date>2017-09-05T14:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Median values from from repeated sampling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393237#M94685</link>
      <description>&lt;P&gt;Anytime, glad to help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And thank you for posting a clear question with sample data and desired output data. That makes it easy to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 14:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393237#M94685</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-09-05T14:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Median values from from repeated sampling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393276#M94691</link>
      <description>&lt;P&gt;And an alternate solution:&lt;/P&gt;
&lt;PRE&gt;proc summary data=have nway;
   class SiteId  SampleDate;
   var Concentration;
   output out=want (drop=_:) median=Med_conc n=SampleN;
run;&lt;/PRE&gt;
&lt;P&gt;And I second &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;'s thanks for good question style AND that the example data will create the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One advantage that Proc summary has that an SQL solution won't is the ability to create many summary statistic variables without having to explicitly name each one using the&amp;nbsp; / autoname option. You may find this handy when you have 20 variables to summarize and want mean, median , max , min, n, std and IQR for each, plus the ability to get more quantiles than SQL allows&amp;nbsp;if needed.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 15:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Median-values-from-from-repeated-sampling/m-p/393276#M94691</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-05T15:52:30Z</dc:date>
    </item>
  </channel>
</rss>

