<?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: cumulative stats such as median in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480768#M124264</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/99946"&gt;@csetzkorn&lt;/a&gt;&amp;nbsp;Yes, the bigger subscript makes sure values(elements doesn't go out of range.&lt;/P&gt;&lt;P&gt;For example, if you believe there could be 10000 records per gadgetid&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jul 2018 11:43:51 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-07-24T11:43:51Z</dc:date>
    <item>
      <title>cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480472#M124185</link>
      <description>&lt;P&gt;I have a dataset, which contains:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;,GadgetId&lt;/P&gt;&lt;P&gt;,SomeMeasurement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to calculate the median of &lt;SPAN&gt;SomeMeasurement for every month whilst considering the retrospective/previous&amp;nbsp;data. Example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;GadgetId&lt;/TD&gt;&lt;TD&gt;SomeMeasurement&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;31-Jan-15&lt;/TD&gt;&lt;TD&gt;A1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t;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;07-Feb-15&lt;/TD&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;03-Feb-15&lt;/TD&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In month&amp;nbsp;Jan 2015 one would consider the values of this month only to calculate the median. In month Feb 2015 one would consider the values&amp;nbsp;in Jan 2015 and Feb 2015, in Dec 2017 one would consider the data for Dec 2017 and all the previous months etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please note that each dataset contains several&amp;nbsp;GadgetIds so a BY&amp;nbsp;GadgetId would be required I suppose. Also each&amp;nbsp;GadgetId has different&amp;nbsp;number samples/dates (some may only have 1 year's worth of data whereas others&amp;nbsp;may have several year's worth of data).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:39:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480472#M124185</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2018-07-23T15:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480474#M124186</link>
      <description>&lt;P&gt;PROC EXPAND.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480474#M124186</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-23T15:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480476#M124187</link>
      <description>&lt;P&gt;How many "&lt;SPAN&gt;and so on"'s are we talking?&amp;nbsp; I mean you could keep all the values in an array for instance then median each row.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array vals{100} 8;
  retain vals:;
  retain num;
  num=ifn(_n_=1,1,num+1);
  vals{num}=somemeasurement;
  result=median(of vals{*});
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;That is given 100 observations.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am not sure I quote see the logic here though, why doing a rolling median?&amp;nbsp; Would not a monthly or yearly be appropriate?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480476#M124187</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-23T15:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480477#M124188</link>
      <description>&lt;P&gt;And temporary arrays method, make your array 31 to have a full month of data. If you have repeated measurements for a month are they considered the same? I noticed you had two observations for month=1 and 1 for month =3. If you have a variable number per month you may want to standardize or aggregate that somehow first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/27e23c015eae7953eff2" target="_blank"&gt;https://gist.github.com/statgeek/27e23c015eae7953eff2&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;

set sashelp.stocks; 
by stock notsorted;

array p{0:30} _temporary_;


if first.stock then call missing(of p{*});
p{mod(_n_,31)} = open;
lowest = median(of p{*});
highest = max(of p{*});


run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480477#M124188</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-23T15:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480479#M124189</link>
      <description>&lt;P&gt;Thanks. I think this is sas/ets which we do not have )-:&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480479#M124189</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2018-07-23T15:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480480#M124190</link>
      <description>&lt;P&gt;Thanks. It could be 3-4 years worth of data. so in month 12 of year 4 I have to use data of all 4 years to get the median. Please also not that I have to use a BY for different gadgets. Each gadget can have 3-4 years but the amount of data is dynamic - i.e. depends on the gadget.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480480#M124190</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2018-07-23T15:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480481#M124191</link>
      <description>&lt;P&gt;Can you please provide a more complete sample data with gadgets and the rest?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480481#M124191</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-23T15:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480489#M124194</link>
      <description>Done - sorry if it was not clear enough ...</description>
      <pubDate>Mon, 23 Jul 2018 15:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480489#M124194</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2018-07-23T15:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480498#M124198</link>
      <description>&lt;P&gt;You only included one gadget, he asked for a few.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second solution I posted deals with BY groups - see the BY and IF FIRST statement that resets things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/99946"&gt;@csetzkorn&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Done - sorry if it was not clear enough ...&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480498#M124198</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-23T15:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480525#M124200</link>
      <description>&lt;P&gt;Helps when you provide complete and comprehensive samples and details&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Date : date9. gadgetid $ SomeMeasurement;
  format date date9.;
datalines;
31-Jan-15	A1	5
26-Jan-15	A1	3
26-Jan-15	A1	3
26-Jan-15	A1	3
03-Feb-15	A1	5
07-Feb-15	A1	5
07-Feb-15	A1	5
07-Feb-15	A1	4
02-Feb-15	A1	5
02-Feb-15	A1	5
03-Feb-15	A1	5
02-Feb-15	A1	5
07-Feb-15	A1	4
03-Feb-15	A1	5
31-Jan-15	B1	5
26-Jan-15	B1	3
26-Jan-15	B1	3
26-Jan-15	B1	3
03-Feb-15	B1	5
07-Feb-15	B1	5
07-Feb-15	B1	5
07-Feb-15	B1	4
02-Feb-15	B1	5
02-Feb-15	B1	5
03-Feb-15	B1	5
02-Feb-15	B1	5
07-Feb-15	B1	4
03-Feb-15	B1	5
;
run;
data temp;
set have;
by gadgetid;
if first.gadgetid then grp=0;
formatted_date=date;
if  month(date) ne lag(month(date)) then grp+1;
format formatted_date monyy7.;
run;
data want;
_k=_n_;
_c=0;
array t(20) _temporary_ ;/*array subscript arbitrary,should assign a big one to hold*/
call missing(median,of t(*));
do  until(last.gadgetid);
do  until(last.grp);
set temp;
by gadgetid grp;
_c+1;
t(_c)=SomeMeasurement;
if last.grp then do; median=median(median,of t(*));output;end;
end;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 16:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480525#M124200</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-23T16:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480548#M124207</link>
      <description>&lt;P&gt;slight correction to the data want step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
_k=_n_;
_c=0;
array t(20) _temporary_ ;/*array subscript arbitrary,should assign a big one to hold*/
call missing(median,of t(*));
do  until(last.gadgetid);
do  until(last.grp);
set temp;
by gadgetid grp;
_c+1;
t(_c)=SomeMeasurement;
if last.grp then do; median=median(of t(*));output;end;
end;
end;
drop _: grp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 17:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480548#M124207</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-23T17:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480582#M124218</link>
      <description>&lt;P&gt;yes there could be several values per day as indicated in the example.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 18:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480582#M124218</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2018-07-23T18:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480728#M124252</link>
      <description>Thanks. Does "should assign a big one" mean that i can assign one which is bigger then what is needed, just in case?</description>
      <pubDate>Tue, 24 Jul 2018 07:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480728#M124252</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2018-07-24T07:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480768#M124264</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/99946"&gt;@csetzkorn&lt;/a&gt;&amp;nbsp;Yes, the bigger subscript makes sure values(elements doesn't go out of range.&lt;/P&gt;&lt;P&gt;For example, if you believe there could be 10000 records per gadgetid&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 11:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480768#M124264</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-24T11:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative stats such as median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480780#M124271</link>
      <description>&lt;P&gt;If you have SAS9.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Date : date9. gadgetid $ SomeMeasurement;
  new_date=intnx('month',date,0);
  format date new_date date9.;
datalines;
31-Jan-15	A1	5
26-Jan-15	A1	3
26-Jan-15	A1	3
26-Jan-15	A1	3
03-Feb-15	A1	5
07-Feb-15	A1	5
07-Feb-15	A1	5
07-Feb-15	A1	4
02-Feb-15	A1	5
02-Feb-15	A1	5
03-Feb-15	A1	5
02-Feb-15	A1	5
07-Feb-15	A1	4
03-Feb-15	A1	5
31-Jan-15	B1	5
26-Jan-15	B1	3
26-Jan-15	B1	3
26-Jan-15	B1	3
03-Feb-15	B1	5
07-Feb-15	B1	5
07-Feb-15	B1	5
07-Feb-15	B1	4
02-Feb-15	B1	5
02-Feb-15	B1	5
03-Feb-15	B1	5
02-Feb-15	B1	5
07-Feb-15	B1	4
03-Feb-15	B1	5
;
run;
proc sql;
create table want as
 select *,(select median(SomeMeasurement) from have 
where gadgetid=a.gadgetid and new_date&amp;lt;=a.new_date) as median
  from have as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jul 2018 12:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulative-stats-such-as-median/m-p/480780#M124271</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-24T12:41:20Z</dc:date>
    </item>
  </channel>
</rss>

