<?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: Finding Threshold Observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/569913#M160659</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277509"&gt;@alexgouv&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your dataset is sorted on Region + SalesPct descending, and count is in ascending order within the region, then the following code will do the work;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Region='New York'; Account='Name1'; Salespct=12.5; RunningTotal=12.5; count=1; output;
Region='New York'; Account='Name2'; Salespct=10; RunningTotal=22.5; count=2; output;
Region='New York'; Account='Name3'; Salespct=20; RunningTotal=42.5; count=3; output;
Region='New York'; Account='Name4'; Salespct=17.5; RunningTotal=60; count=4; output;
Region='Omaha'; Account='Name2'; Salespct=7.5; RunningTotal=7.5; count=1; output;
Region='Omaha'; Account='Name2'; Salespct=20.5; RunningTotal=27.5; count=2; output;
Region='Omaha'; Account='Name2'; Salespct=12.5; RunningTotal=40; count=2; output;
run;

data want (drop=Salespct RunningTotal) ; set have; by region;
	if RunningTotal &amp;gt;= 25 and lag(RunningTotal) &amp;lt; 25 then output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- and next time &lt;STRONG&gt;&lt;EM&gt;please&lt;/EM&gt;&lt;/STRONG&gt; supply code to create an input data set. Often the better part of the time used to answer a question is taken up by preparing some data to use for testing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2019 17:49:24 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2019-06-28T17:49:24Z</dc:date>
    <item>
      <title>Finding Threshold Observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/569903#M160655</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I am stuck on a problem where I need to find how many accounts make up the top 25% of sales by region.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now I have the data in this format:&lt;/P&gt;&lt;P&gt;Region&amp;nbsp; &amp;nbsp; &amp;nbsp;Account&amp;nbsp; &amp;nbsp; &amp;nbsp;% of Regional Sales&amp;nbsp; &amp;nbsp; &amp;nbsp;Running total of % of Regional Sales&amp;nbsp; &amp;nbsp; &amp;nbsp;Count&lt;/P&gt;&lt;P&gt;New York&amp;nbsp; &amp;nbsp; &amp;nbsp; "Name"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;New York&amp;nbsp; &amp;nbsp; &amp;nbsp; "Name2"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;There are multiple different regions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need to do is figure out which observation pushes the running total of % above that threshold of 25% and then output the count variable for that observation. IE I am trying to find out how many accounts it took to get 25% of the sales for the New York region. Then the same for each subsequent region.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 17:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/569903#M160655</guid>
      <dc:creator>alexgouv</dc:creator>
      <dc:date>2019-06-28T17:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Threshold Observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/569913#M160659</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277509"&gt;@alexgouv&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your dataset is sorted on Region + SalesPct descending, and count is in ascending order within the region, then the following code will do the work;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Region='New York'; Account='Name1'; Salespct=12.5; RunningTotal=12.5; count=1; output;
Region='New York'; Account='Name2'; Salespct=10; RunningTotal=22.5; count=2; output;
Region='New York'; Account='Name3'; Salespct=20; RunningTotal=42.5; count=3; output;
Region='New York'; Account='Name4'; Salespct=17.5; RunningTotal=60; count=4; output;
Region='Omaha'; Account='Name2'; Salespct=7.5; RunningTotal=7.5; count=1; output;
Region='Omaha'; Account='Name2'; Salespct=20.5; RunningTotal=27.5; count=2; output;
Region='Omaha'; Account='Name2'; Salespct=12.5; RunningTotal=40; count=2; output;
run;

data want (drop=Salespct RunningTotal) ; set have; by region;
	if RunningTotal &amp;gt;= 25 and lag(RunningTotal) &amp;lt; 25 then output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- and next time &lt;STRONG&gt;&lt;EM&gt;please&lt;/EM&gt;&lt;/STRONG&gt; supply code to create an input data set. Often the better part of the time used to answer a question is taken up by preparing some data to use for testing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 17:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/569913#M160659</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-06-28T17:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Threshold Observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/569916#M160660</link>
      <description>Provide a full sample data set with expected output, preferable as a data step and someone can help you with the code. Some IF/THEN statements. Include more than one region since you need it by region as well, otherwise the answer won't generalize.</description>
      <pubDate>Fri, 28 Jun 2019 17:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/569916#M160660</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-28T17:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Threshold Observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/570001#M160701</link>
      <description>&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 21:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Threshold-Observation/m-p/570001#M160701</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-28T21:29:43Z</dc:date>
    </item>
  </channel>
</rss>

