<?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 numner in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572312#M161510</link>
    <description>&lt;P&gt;Just for fun, you can use a hash object to achieve the same thing without sorting your data if you want to preserve the original order of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do;
    dcl hash h();
    h.defineKey ("division", "group", "file");
    h.defineData ("Seq");
    h.defineDone ();
  end;
 
  set test;

  if h.find() ne 0 then Seq = 1;
  else                  Seq + 1;

  h.replace();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 10 Jul 2019 10:17:52 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-07-10T10:17:52Z</dc:date>
    <item>
      <title>Sequence numner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572309#M161508</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to add sequence number based on 3 columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input division$ group$ file$;
datalines;
a t1 1
b m2 5
a t1 1
b m2 5
a t2 3
a t2 3
a t2 4
b m2 6
a t1 2
b m1 6
b m1 6
a t2 4
;

proc sort data=test;
	by division group file;
run;

data want;
	set test;
	by division group;
	Seq+1;
	if first.group  then Seq=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to see the sequence like in the last column, based on the group and file&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result.JPG" style="width: 425px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30908i4EA89EDF7C39AAC4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Result.JPG" alt="Result.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 10:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572309#M161508</guid>
      <dc:creator>nv1950</dc:creator>
      <dc:date>2019-07-10T10:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence numner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572311#M161509</link>
      <description>&lt;P&gt;Welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use file instead of group like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=test;
	by division group file;
run;

data want;
	set test;
	by division group file;
	Seq+1;
	if first.file  then Seq=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jul 2019 10:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572311#M161509</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-07-10T10:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence numner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572312#M161510</link>
      <description>&lt;P&gt;Just for fun, you can use a hash object to achieve the same thing without sorting your data if you want to preserve the original order of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do;
    dcl hash h();
    h.defineKey ("division", "group", "file");
    h.defineData ("Seq");
    h.defineDone ();
  end;
 
  set test;

  if h.find() ne 0 then Seq = 1;
  else                  Seq + 1;

  h.replace();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jul 2019 10:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572312#M161510</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-07-10T10:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence numner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572317#M161511</link>
      <description>&lt;P&gt;Thank you. This worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Initially I have the data for the same record in 2 separate columns. So I am adding the sequence number first, then use proc sql min case to bring the records from row 1 and row to&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;min(case when Seq = 1 then data end)as &lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;data&lt;/SPAN&gt;1,&lt;/P&gt;&lt;P&gt;min(case when Seq = 2 then &lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;data &lt;/SPAN&gt;end)as &lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;data&lt;/SPAN&gt;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure if there is any easier or quicker way, below is my final output, where the data moved from 2 separate rows into one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result.JPG" style="width: 412px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30909i9A85A44CC0E3D9A3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Result.JPG" alt="Result.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 10:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572317#M161511</guid>
      <dc:creator>nv1950</dc:creator>
      <dc:date>2019-07-10T10:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence numner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572326#M161512</link>
      <description>&lt;P&gt;Another way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
input division$ group$ file$;
datalines;
a t1 1
b m2 5
a t1 1
b m2 5
a t2 3
a t2 3
a t2 4
b m2 6
a t1 2
b m1 6
b m1 6
a t2 4
;
run;

proc sort data = test;
by division group file;
run;

data need;
   set test;
   retain pstr;
   length str pstr $4;
   str = cats(division,group,file);
   if pstr = str then seq + 1;
   else if pstr ^= str then do; seq = 1; pstr = str; end;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jul 2019 11:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-numner/m-p/572326#M161512</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-07-10T11:47:40Z</dc:date>
    </item>
  </channel>
</rss>

