<?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: Reg:Clustering if obs is same new unique number to generate in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Clustering-if-obs-is-same-new-unique-number-to-generate/m-p/56937#M15920</link>
    <description>If you care the origin order of the dataset. Then try to use Hash Table.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data new;&lt;BR /&gt;
input acc_no amt;&lt;BR /&gt;
cards;&lt;BR /&gt;
1012 23&lt;BR /&gt;
1013 45&lt;BR /&gt;
1012 56&lt;BR /&gt;
1012 56&lt;BR /&gt;
1013 80&lt;BR /&gt;
1023 42&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data new(drop=rc);&lt;BR /&gt;
 declare hash ha(hashexp:10);&lt;BR /&gt;
  ha.definekey('acc_no');&lt;BR /&gt;
  ha.definedata('seq_no');&lt;BR /&gt;
  ha.definedone();&lt;BR /&gt;
&lt;BR /&gt;
 do until(last);&lt;BR /&gt;
  set new end=last;&lt;BR /&gt;
  rc=ha.find();&lt;BR /&gt;
  if rc ne 0 then seq_no+1;&lt;BR /&gt;
  rc=ha.add();&lt;BR /&gt;
  output;&lt;BR /&gt;
 end;&lt;BR /&gt;
stop;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Wed, 27 Apr 2011 01:47:10 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-04-27T01:47:10Z</dc:date>
    <item>
      <title>Reg:Clustering if obs is same new unique number to generate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Clustering-if-obs-is-same-new-unique-number-to-generate/m-p/56935#M15918</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
Iam having acc_no with same number now i want a new variable as seq_no it should be same for all the accouns that are same:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data new;&lt;BR /&gt;
input acc_no amt;&lt;BR /&gt;
cards;&lt;BR /&gt;
1012 23&lt;BR /&gt;
1013 45&lt;BR /&gt;
1012 56&lt;BR /&gt;
1012 56&lt;BR /&gt;
1013 80&lt;BR /&gt;
1023 42&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
output:&lt;BR /&gt;
&lt;BR /&gt;
acc_no amt seq_no &lt;BR /&gt;
1012    23     1&lt;BR /&gt;
1013    45     2&lt;BR /&gt;
1012    56     1&lt;BR /&gt;
1012    56     1&lt;BR /&gt;
1013    80     2&lt;BR /&gt;
1023    42     3&lt;BR /&gt;
&lt;BR /&gt;
For this the acc no 1012 is having 1 as seq_no ,and 1013 has 2 as seq_no like that.</description>
      <pubDate>Tue, 26 Apr 2011 14:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Clustering-if-obs-is-same-new-unique-number-to-generate/m-p/56935#M15918</guid>
      <dc:creator>R_Win</dc:creator>
      <dc:date>2011-04-26T14:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Reg:Clustering if obs is same new unique number to generate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Clustering-if-obs-is-same-new-unique-number-to-generate/m-p/56936#M15919</link>
      <description>Hello R_Win,&lt;BR /&gt;
&lt;BR /&gt;
This is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data i;&lt;BR /&gt;
input acc_no amt;&lt;BR /&gt;
i+1;&lt;BR /&gt;
cards;&lt;BR /&gt;
1012 23&lt;BR /&gt;
1013 45&lt;BR /&gt;
1012 56&lt;BR /&gt;
1012 56&lt;BR /&gt;
1013 80&lt;BR /&gt;
1023 42&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=i;&lt;BR /&gt;
  by acc_no;&lt;BR /&gt;
run;&lt;BR /&gt;
data r;&lt;BR /&gt;
  set i;&lt;BR /&gt;
  if First.acc_no then seq_no+1;&lt;BR /&gt;
  by acc_no;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=r out=r(drop=i);&lt;BR /&gt;
  by i;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
If it is not necessary to keep the same order of observations in the input and output datasets then variable i can be deleted along side with the last sorting. &lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 26 Apr 2011 14:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Clustering-if-obs-is-same-new-unique-number-to-generate/m-p/56936#M15919</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-26T14:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Reg:Clustering if obs is same new unique number to generate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Clustering-if-obs-is-same-new-unique-number-to-generate/m-p/56937#M15920</link>
      <description>If you care the origin order of the dataset. Then try to use Hash Table.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data new;&lt;BR /&gt;
input acc_no amt;&lt;BR /&gt;
cards;&lt;BR /&gt;
1012 23&lt;BR /&gt;
1013 45&lt;BR /&gt;
1012 56&lt;BR /&gt;
1012 56&lt;BR /&gt;
1013 80&lt;BR /&gt;
1023 42&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data new(drop=rc);&lt;BR /&gt;
 declare hash ha(hashexp:10);&lt;BR /&gt;
  ha.definekey('acc_no');&lt;BR /&gt;
  ha.definedata('seq_no');&lt;BR /&gt;
  ha.definedone();&lt;BR /&gt;
&lt;BR /&gt;
 do until(last);&lt;BR /&gt;
  set new end=last;&lt;BR /&gt;
  rc=ha.find();&lt;BR /&gt;
  if rc ne 0 then seq_no+1;&lt;BR /&gt;
  rc=ha.add();&lt;BR /&gt;
  output;&lt;BR /&gt;
 end;&lt;BR /&gt;
stop;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 27 Apr 2011 01:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Clustering-if-obs-is-same-new-unique-number-to-generate/m-p/56937#M15920</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-27T01:47:10Z</dc:date>
    </item>
  </channel>
</rss>

