<?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: sequence in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313904#M68283</link>
    <description>&lt;P&gt;1) Create a list of unique Ids&lt;/P&gt;
&lt;P&gt;2) Attribute distinct numbers to every Id&lt;/P&gt;
&lt;P&gt;3) Add these numbers to original data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id;
length otherData $12;
otherData = catx(" ", "Other Data", _n_); 
cards;
101
102
103
104
101
102
101
103
;

proc sql;
create table ids as
select unique id from have;
quit;

data idsSeq;
set ids;
seq +1;
run;

proc sql;
create table want as
select have.id, otherData, seq
from have natural join idsSeq;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Nov 2016 22:25:48 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-11-23T22:25:48Z</dc:date>
    <item>
      <title>sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313759#M68224</link>
      <description>&lt;P&gt;Suppose I have d column in a sas dataset ,I need create a new dataset which contain the id column along with seq column&amp;nbsp;&lt;/P&gt;&lt;P&gt;for id 101 the seq is 1 for 102 it is 2....if 101 again gets repeated the seq should be 1,for 102 it should be 2 ...The first assigned seq num should be repeated if same ids are repeated ..&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; seq&lt;BR /&gt;101 &amp;nbsp; 1&lt;BR /&gt;102 &amp;nbsp; 2&lt;BR /&gt;103 &amp;nbsp; 3&lt;BR /&gt;104 &amp;nbsp; 4&lt;BR /&gt;101 &amp;nbsp; 1&lt;BR /&gt;102 &amp;nbsp; 2&lt;BR /&gt;101 &amp;nbsp; 1&lt;BR /&gt;103 &amp;nbsp; 3&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 12:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313759#M68224</guid>
      <dc:creator>molla</dc:creator>
      <dc:date>2016-11-23T12:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313760#M68225</link>
      <description>&lt;P&gt;Sort your data by ID, then do:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  by id;
  retain seq;
  seq=ifn(first.id,sum(seq,1),seq);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 12:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313760#M68225</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-23T12:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313762#M68227</link>
      <description>&lt;P&gt;Part of the following code might not be necessary, if you do not need to preserve the orginal order:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id;
cards;
101
102
103
104
101
102
101
103
;
run;

data have;
set have;
order + 1;
run;

proc sort data=have;
by id;
run;

data want;
set have;
by id;
if first.id then seq + 1;
run;

proc sort data=want;
by order;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 12:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313762#M68227</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-23T12:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313904#M68283</link>
      <description>&lt;P&gt;1) Create a list of unique Ids&lt;/P&gt;
&lt;P&gt;2) Attribute distinct numbers to every Id&lt;/P&gt;
&lt;P&gt;3) Add these numbers to original data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id;
length otherData $12;
otherData = catx(" ", "Other Data", _n_); 
cards;
101
102
103
104
101
102
101
103
;

proc sql;
create table ids as
select unique id from have;
quit;

data idsSeq;
set ids;
seq +1;
run;

proc sql;
create table want as
select have.id, otherData, seq
from have natural join idsSeq;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 22:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313904#M68283</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-23T22:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313916#M68291</link>
      <description>&lt;P&gt;An approach using a hash table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id;
  cards;
101
102
103
104
101
102
101
103
;
run;

data want(drop=_:);
  set have;
  if _n_=1 then
    do;
      length seq 8;
      dcl hash h1();
      h1.defineKey('id');
      h1.defineData('seq');
      h1.defineDone();
    end;

  if h1.find() ne 0 then
    do;
      _seq+1;
      seq=_seq;
      h1.add();
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 23:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313916#M68291</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-23T23:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313938#M68302</link>
      <description>You could also take advantage of the num_items attribute of hash objects:&lt;BR /&gt;&lt;BR /&gt;if h1.find() ne 0 then&lt;BR /&gt;    do;&lt;BR /&gt;      seq=h1.num_items+1;&lt;BR /&gt;      h1.add();&lt;BR /&gt;    end;&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Nov 2016 01:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sequence/m-p/313938#M68302</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-24T01:19:36Z</dc:date>
    </item>
  </channel>
</rss>

