<?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: Find threshold value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644580#M192554</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ASP_New = 'ASP Ceil'n;
temp = lag(asp_new);
if '% Units'n &amp;gt;=.98 then ASP_New = temp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You're aware that PROC RANK can calculate the ranks for you? And that you can use variable labels instead of variable names to avoid having to have variables such as '% Ceil'n?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 May 2020 18:14:25 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-05-01T18:14:25Z</dc:date>
    <item>
      <title>Find threshold value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644571#M192545</link>
      <description>&lt;P&gt;Howdy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running some code that will sort products by price, tally a cumulative percent of units, and then create quartiles based on the cumulative percentage.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, what I also want to do is create a new price variable that "caps" the price because there are some really whacky high prices that I do not want to come through.&amp;nbsp; What I am trying to do is find when the cumulative unit percentage crosses 98% and then only use that price going forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code.&amp;nbsp; The bottom part is the incorrect part.&amp;nbsp; I know i'm using the lag function improperly.&amp;nbsp; Any help is greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jeff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ata work.asp_range_03;
	set work.asp_range_02;
	by ProdLvl_1 ProdLvl_2 ProdLvl_3 ProdLvl_4 'asp ceil'n;
    
    /* Calculate running total of Units */ 
	if first.ProdLvl_4 then Cum_Units =0;
	Cum_Units + Units;

	/* Running % of total units */
	'% Units'n = Cum_Units/'Total Units'n;

	/* Identify quartiles.  Descending order prevents quartile skipping */
	if '% Units'n &amp;gt;=.75 then Quartile=4;
	else if '% Units'n &amp;gt;=.50 then Quartile=3;
	else if '% Units'n &amp;gt;=.25 then Quartile=2;
	else Quartile=1;

	/* Cap maximum ASP Ceil */
	ASP_New = 'ASP Ceil'n;
	if '% Units'n &amp;gt;=.98 then ASP_New = Lag(ASP_New);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 May 2020 18:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644571#M192545</guid>
      <dc:creator>JeffM1968</dc:creator>
      <dc:date>2020-05-01T18:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find threshold value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644578#M192552</link>
      <description>&lt;P&gt;I haven't tried finding out what is wrong with your LAG function usage.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you want to determine where 98% of the data lies, you should use &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p0le3p5ngj1zlbn1mh3tistq9t76.htm&amp;amp;locale=en" target="_self"&gt;PROC RANK&lt;/A&gt; with&amp;nbsp; the FRACTION option. This will enable you to see what data lies in the lower 98%. An alternative is &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=procstat&amp;amp;docsetTarget=procstat_univariate_syntax21.htm&amp;amp;locale=en" target="_self"&gt;PROC UNIVARIATE&lt;/A&gt; which will&amp;nbsp; give you the 98th percentile.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 18:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644578#M192552</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-01T18:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Find threshold value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644580#M192554</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ASP_New = 'ASP Ceil'n;
temp = lag(asp_new);
if '% Units'n &amp;gt;=.98 then ASP_New = temp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You're aware that PROC RANK can calculate the ranks for you? And that you can use variable labels instead of variable names to avoid having to have variables such as '% Ceil'n?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 18:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644580#M192554</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-01T18:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find threshold value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644584#M192556</link>
      <description>&lt;P&gt;I am not that familiar with some of the PROC procedures.&amp;nbsp; I usually develop in EG and then convert to code.&amp;nbsp; I'll have to look into some of them!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 18:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644584#M192556</guid>
      <dc:creator>JeffM1968</dc:creator>
      <dc:date>2020-05-01T18:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Find threshold value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644588#M192558</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326547"&gt;@JeffM1968&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you can simply correct your existing code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either use&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if '% Units'n &amp;gt;=.98 then do;
  if _tmp=.m then _tmp=ASP_New;
  ASP_New=_tmp;
end;
retain _tmp .m;
drop _tmp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if you want to carry forward the &lt;FONT face="courier new,courier"&gt;ASP_New&lt;/FONT&gt; value of the first observation with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'% Units'n &amp;gt;=.98&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;lag_ASP_New=lag(ASP_New);
if '% Units'n &amp;gt;=.98 then do;
  if _tmp=.m then _tmp=lag_ASP_New;
  ASP_New=_tmp;
end;
retain _tmp .m;
drop _tmp lag_ASP_New;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if you want to carry forward the &lt;FONT face="courier new,courier"&gt;ASP_New&lt;/FONT&gt; value of the observation &lt;EM&gt;before&lt;/EM&gt; the first observation with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'% Units'n &amp;gt;=.98&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 19:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-threshold-value/m-p/644588#M192558</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-05-01T19:10:15Z</dc:date>
    </item>
  </channel>
</rss>

