<?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: Calculate percentile for target date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796242#M255489</link>
    <description>&lt;P&gt;My array is TEMPORARY array unlike yours VECTOR array which waste too many resource of PC ,but they have the same usage for your case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;For me, you code still create array for every row, right?"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes . It is just a temp array out of somewhere . and for every row it is the same for all over time.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"If so the time saving coming only from the pct statement since it is conditional on date=5."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;No. time saving is coming from my temporary array .&lt;/P&gt;</description>
    <pubDate>Tue, 15 Feb 2022 10:06:37 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-02-15T10:06:37Z</dc:date>
    <item>
      <title>Calculate percentile for target date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/795974#M255378</link>
      <description>&lt;P style="margin: 0in; line-height: 15.75pt; background: white;"&gt;&lt;SPAN&gt;Hi Everyone,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&lt;SPAN&gt;My code below calculates moving percentile for each id based on previous 5 day. This is done for every row in the table.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&lt;SPAN&gt;Since I am interested in only the last few date (say date=5), I don't want to calculate for the whole table as it takes time to create the array for all rows in my big data.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white;"&gt;&lt;SPAN&gt;I try to use IF function but it doesn’t work. Look like the array is based on 1 row date=5 instead of previous dates.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&lt;SPAN&gt;Can you please help to fix?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&lt;SPAN&gt;HHC&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; line-height: 15.75pt; background: white; box-sizing: border-box; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; word-spacing: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input date  id $ value;
datalines;
1 a 1
1 b 3
1 c 6
2 a 9
2 b 6
2 c 8
3 a 99
3 b 9
3 c 5
3 d 5
4 a 10
4 b 8
4 c 7
5 a 9
5 b 15
5 c 20
6 a 3
6 b 8
6 c 55
;run;

proc sort data=have; by id date;run;

*Calculate percentile for each id FULL TABLE;
data want; set have;
	*drop aa:;
	array a{0: 4} aa1-aa5;
	a{mod(_n_,5)}=value;
	retain aa:;
		pct_95=pctl(95,of a{*});
run;


*****Calculate percentile for each id For JUST few DATE*******;
data want_short; set have;
if date = 5 then do;
	array a{0: 4} aa1-aa5;
	a{mod(_n_,5)}=value;
	retain aa:;
		pct_95=pctl(95,of a{*});
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Feb 2022 02:53:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/795974#M255378</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-02-14T02:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate percentile for target date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/795977#M255379</link>
      <description>&lt;P&gt;I think code should like :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by id date;run;

*****Calculate percentile for each id For JUST few DATE*******;
data want_short; set have;
by id ;
if first.id then n=0;
n+1;

	array a{0: 4} _temporary_;
	a{mod(n,5)}=value;

if date = 5 then pct_95=pctl(95,of a{*});

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Feb 2022 03:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/795977#M255379</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-02-14T03:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate percentile for target date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796135#M255436</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;
&lt;P&gt;Thanks a lot for helping.&lt;/P&gt;
&lt;P&gt;Your code cut the time of SAS running by immense amount.&lt;/P&gt;
&lt;P&gt;I am not quite understand your code and it would be helpful if you could explain it abit.&lt;/P&gt;
&lt;P&gt;For me, you code still create array for every row, right?&lt;/P&gt;
&lt;P&gt;If so the time saving coming only from the pct statement since it is conditional on date=5.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 20:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796135#M255436</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-02-14T20:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate percentile for target date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796242#M255489</link>
      <description>&lt;P&gt;My array is TEMPORARY array unlike yours VECTOR array which waste too many resource of PC ,but they have the same usage for your case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;For me, you code still create array for every row, right?"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes . It is just a temp array out of somewhere . and for every row it is the same for all over time.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"If so the time saving coming only from the pct statement since it is conditional on date=5."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;No. time saving is coming from my temporary array .&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 10:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796242#M255489</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-02-15T10:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate percentile for target date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796449#M255576</link>
      <description>&lt;P&gt;Thanks for the explanation.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 04:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796449#M255576</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-02-16T04:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate percentile for target date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796454#M255579</link>
      <description>&lt;P&gt;Another alternative is to sort by id/date as per&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;, but instead of an array, use&amp;nbsp; value, lag(value),...,lag4(value) as the arguments of the PCTL function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input date  id $ value;
datalines;
1 a 1
1 b 3
1 c 6
2 a 9
2 b 6
2 c 8
3 a 99
3 b 9
3 c 5
3 d 5
4 a 10
4 b 8
4 c 7
5 a 9
5 b 15
5 c 20
6 a 3
6 b 8
6 c 55
;run;

proc sort data=have out=need;
  by id date;
run;

data want;
  set need;
  by id;
  pctl_95=pctl(95,value,lag(value),lag2(value),lag3(value),lag4(value));
  if lag4(id)^=id then call missing(pctl_95);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Feb 2022 23:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-percentile-for-target-date/m-p/796454#M255579</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-02-17T23:27:38Z</dc:date>
    </item>
  </channel>
</rss>

