<?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: creating dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9913#M619</link>
    <description>Sorry I don't understand what you are looking for, I wrote the code below but this does not result in what you have. Can you explain a bit more. Do you mean the sum of all the previous values, all the values since the rank was incremented, the last two values? &lt;BR /&gt;
&lt;BR /&gt;
data ranked;&lt;BR /&gt;
retain rank 1 sum_vals;&lt;BR /&gt;
set dpd;&lt;BR /&gt;
sum_vals+bucket;&lt;BR /&gt;
if sum_vals&amp;gt;6 then do;&lt;BR /&gt;
   rank+1;&lt;BR /&gt;
   sum_vals=0;&lt;BR /&gt;
end;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 24 Mar 2009 09:35:18 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-24T09:35:18Z</dc:date>
    <item>
      <title>creating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9912#M618</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
i have data set like :&lt;BR /&gt;
data dpd;&lt;BR /&gt;
input bucket;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1&lt;BR /&gt;
2&lt;BR /&gt;
5&lt;BR /&gt;
6&lt;BR /&gt;
7&lt;BR /&gt;
8&lt;BR /&gt;
9&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
7&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
if sum of that values are &amp;gt;6 then rank value=1 and it will be incremented.&lt;BR /&gt;
i want to create a dataset  like below:::&lt;BR /&gt;
&lt;BR /&gt;
bucket  rank&lt;BR /&gt;
1           1&lt;BR /&gt;
2           1&lt;BR /&gt;
5           1&lt;BR /&gt;
6           2&lt;BR /&gt;
7           2&lt;BR /&gt;
8           3&lt;BR /&gt;
9           4&lt;BR /&gt;
3           5&lt;BR /&gt;
4           5&lt;BR /&gt;
7           6</description>
      <pubDate>Tue, 24 Mar 2009 06:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9912#M618</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T06:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: creating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9913#M619</link>
      <description>Sorry I don't understand what you are looking for, I wrote the code below but this does not result in what you have. Can you explain a bit more. Do you mean the sum of all the previous values, all the values since the rank was incremented, the last two values? &lt;BR /&gt;
&lt;BR /&gt;
data ranked;&lt;BR /&gt;
retain rank 1 sum_vals;&lt;BR /&gt;
set dpd;&lt;BR /&gt;
sum_vals+bucket;&lt;BR /&gt;
if sum_vals&amp;gt;6 then do;&lt;BR /&gt;
   rank+1;&lt;BR /&gt;
   sum_vals=0;&lt;BR /&gt;
end;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 24 Mar 2009 09:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9913#M619</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T09:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: creating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9914#M620</link>
      <description>This is My dataset &lt;BR /&gt;
data dpd;&lt;BR /&gt;
input bucket;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1&lt;BR /&gt;
2&lt;BR /&gt;
5&lt;BR /&gt;
6&lt;BR /&gt;
7&lt;BR /&gt;
8&lt;BR /&gt;
9&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
7&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
The output:&lt;BR /&gt;
Bucket  rank&lt;BR /&gt;
1              1        &lt;BR /&gt;
2              1&lt;BR /&gt;
5              1&lt;BR /&gt;
6              2&lt;BR /&gt;
7              2&lt;BR /&gt;
8              3&lt;BR /&gt;
9              4&lt;BR /&gt;
3              5&lt;BR /&gt;
4              5&lt;BR /&gt;
7              6&lt;BR /&gt;
&lt;BR /&gt;
in the above output &lt;BR /&gt;
first =&amp;gt;   add the values up to &amp;gt; 6 :     1+2+5 &amp;gt;6 &lt;BR /&gt;
rank value is 1 for 3 observations  =1&lt;BR /&gt;
&lt;BR /&gt;
second=&amp;gt;  add the values up to &amp;gt;6 :   6+7 &amp;gt;6&lt;BR /&gt;
   rank value is 2 for 2 observations  =2 &lt;BR /&gt;
&lt;BR /&gt;
third =&amp;gt;  add the values up to &amp;gt; 6 :   8 &amp;gt;6 &lt;BR /&gt;
rank value is 3 for 1 observations  =3 &lt;BR /&gt;
&lt;BR /&gt;
fourth=&amp;gt;  add the values up to &amp;gt; 6:   9 &amp;gt;6 &lt;BR /&gt;
rank value is 4 for 1 observations  =4&lt;BR /&gt;
&lt;BR /&gt;
fith=&amp;gt;  add the values up to &amp;gt; 6:   3+4 &amp;gt;6 &lt;BR /&gt;
rank value is 5 for 2 observations  =5&lt;BR /&gt;
&lt;BR /&gt;
sixth=&amp;gt;  add the values up to &amp;gt; 6   7 &amp;gt;6 &lt;BR /&gt;
rank value is 6 for 1 observations  =6</description>
      <pubDate>Tue, 24 Mar 2009 09:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9914#M620</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T09:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: creating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9915#M621</link>
      <description>You should be able to do this with retain statement if I understand it correctly.&lt;BR /&gt;
Just make sure that you do the output before increasing the rank count.&lt;BR /&gt;
eg:&lt;BR /&gt;
&lt;BR /&gt;
data test(drop=total);&lt;BR /&gt;
  set dpd;&lt;BR /&gt;
  retain total 0 group 1;&lt;BR /&gt;
  total=total+bucket;&lt;BR /&gt;
  output;&lt;BR /&gt;
  if total&amp;gt;6 then do;&lt;BR /&gt;
    group=group+1;&lt;BR /&gt;
	total=0;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 24 Mar 2009 10:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9915#M621</guid>
      <dc:creator>Jao</dc:creator>
      <dc:date>2009-03-24T10:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: creating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9916#M622</link>
      <description>Thanks for clearing that up. My code would almost have done it, just shift the sum statement below the logic which checks it's value.&lt;BR /&gt;
&lt;BR /&gt;
data ranked;&lt;BR /&gt;
retain rank 1 sum_vals;&lt;BR /&gt;
set dpd;&lt;BR /&gt;
if sum_vals&amp;gt;6 then do;&lt;BR /&gt;
rank+1;&lt;BR /&gt;
sum_vals=0;&lt;BR /&gt;
end;&lt;BR /&gt;
sum_vals+bucket;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 24 Mar 2009 11:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-dataset/m-p/9916#M622</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T11:10:05Z</dc:date>
    </item>
  </channel>
</rss>

