<?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: Looping code to sort into Quantiles in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625868#M20296</link>
    <description>&lt;P&gt;What does you log say? When it sees the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %let groupno=&amp;amp;I;&lt;/P&gt;
&lt;P&gt;doesn't SAs object saying "WARNING: Apparent symbolic reference I not resolved.".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apparently (you haven't provided any sample input data) you have incoming data obs with variables TOTAL_A and CUMULATIVE_A.&amp;nbsp; And you merely want to assign a group number to the obs based on the ratio of CUMULATIVE_A/TOTAL_A. categorizing into &amp;amp;N equal-size ranges.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that CUMULATIVE_A always more than zero, but never more than TOTAL_A then you have a very straightforward task:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let N=10;
data weighted;
  set OGDATA;
  groupno =  ceil(cumulative_a/(total_a/&amp;amp;N));
run;&lt;/CODE&gt;&lt;/PRE&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Feb 2020 15:22:05 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-02-19T15:22:05Z</dc:date>
    <item>
      <title>Looping code to sort into Quantiles</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625821#M20291</link>
      <description>&lt;P&gt;I previosly made a programme that sorts a large group of data into 10 equal parts , weighted by theyre values for feild A .&lt;/P&gt;&lt;P&gt;I have been trying to recreate it so that it works for any amount of equal parts .&lt;/P&gt;&lt;P&gt;here is my code for sorting the groups .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*setting = 10 as an example*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; n = 10;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Weighted ; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; OGDATA; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; GroupNo=&amp;amp;i;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;Format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;Do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;while&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (i&amp;lt;&amp;amp;n);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Cumulative_A &amp;lt; (((i-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;)/&amp;amp;n)*(Total_A))&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;Then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"Group &amp;amp;GroupNo"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;Total_A&amp;nbsp;Cumulative_A Group A ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;summary&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=Weighted ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;var&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;Total_A&amp;nbsp;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;out&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=SummaryBand &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;sum&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= ; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ; &lt;/FONT&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;FONT face="Courier New" size="3"&gt;PROBLEMS : &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;code doesnt split the data correctly , it only gives G&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 12:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625821#M20291</guid>
      <dc:creator>Gval99</dc:creator>
      <dc:date>2020-02-19T12:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Looping code to sort into Quantiles</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625831#M20292</link>
      <description>&lt;P&gt;Have you already tried if &lt;A href="https://go.documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=p0le3p5ngj1zlbn1mh3tistq9t76.htm&amp;amp;locale=en" target="_self"&gt;Proc Rank&lt;/A&gt; could do the job for you?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET n = 10;
data have;
  length a b 8;
  do b=1 to 100;
    a=ceil(ranuni(1)*100);
    output;
  end;
  stop;
run;
proc rank data=have out=want groups=&amp;amp;n;
  ranks group;
  var a;
run;
proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 13:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625831#M20292</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-19T13:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Looping code to sort into Quantiles</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625844#M20294</link>
      <description>The problem with this solution is that the total values for A are not the same . The Results should be weighted so that for each group the Sum of A should be equal .&lt;BR /&gt;I did a proc summary of these results and it shows that is just breaks it down into an equal number of rows for A.&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Feb 2020 13:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625844#M20294</guid>
      <dc:creator>Gval99</dc:creator>
      <dc:date>2020-02-19T13:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Looping code to sort into Quantiles</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625868#M20296</link>
      <description>&lt;P&gt;What does you log say? When it sees the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %let groupno=&amp;amp;I;&lt;/P&gt;
&lt;P&gt;doesn't SAs object saying "WARNING: Apparent symbolic reference I not resolved.".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apparently (you haven't provided any sample input data) you have incoming data obs with variables TOTAL_A and CUMULATIVE_A.&amp;nbsp; And you merely want to assign a group number to the obs based on the ratio of CUMULATIVE_A/TOTAL_A. categorizing into &amp;amp;N equal-size ranges.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that CUMULATIVE_A always more than zero, but never more than TOTAL_A then you have a very straightforward task:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let N=10;
data weighted;
  set OGDATA;
  groupno =  ceil(cumulative_a/(total_a/&amp;amp;N));
run;&lt;/CODE&gt;&lt;/PRE&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 15:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-code-to-sort-into-Quantiles/m-p/625868#M20296</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-19T15:22:05Z</dc:date>
    </item>
  </channel>
</rss>

