<?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: How to obtain the 1st sequence number in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145183#M38568</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PROC SQL APPROACH，raw data stolen from PG&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;input id $ DateA :mmddyy10. SeqA;&lt;/P&gt;&lt;P&gt;format dateA yymmdd10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1a. 03/01/2014 123&lt;/P&gt;&lt;P&gt;2a. 03/02/2014 234&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data b;&lt;/P&gt;&lt;P&gt;input id $ DateB :mmddyy10. SeqB;&lt;/P&gt;&lt;P&gt;format dateB yymmdd10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1a. 03/01/2014&amp;nbsp; 122&lt;/P&gt;&lt;P&gt;1a. 03/01/2014&amp;nbsp; 121&lt;/P&gt;&lt;P&gt;1a. 03/04/2014&amp;nbsp; 124&lt;/P&gt;&lt;P&gt;2a. 03/02/2014&amp;nbsp; 235&lt;/P&gt;&lt;P&gt;2a. 03/01/2014&amp;nbsp; 233&lt;/P&gt;&lt;P&gt;2a. 03/01/2014&amp;nbsp; 232&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE WANT AS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT A.ID, DATEA, (SELECT MAX(SEQB) FROM B WHERE A.ID=B.ID AND B.SEQB &amp;lt; A.SEQA GROUP BY B.ID) AS SEQ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; FROM A;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 16 Mar 2014 02:40:30 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2014-03-16T02:40:30Z</dc:date>
    <item>
      <title>How to obtain the 1st sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145181#M38566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI I have and issue on how to obtain the first sequence number base of another sequence # for example...&lt;/P&gt;&lt;P&gt;i Have one table with data that looks like this &lt;/P&gt;&lt;P&gt;id.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Seq no.&lt;/P&gt;&lt;P&gt;1a. 03/01/2014. 123&lt;/P&gt;&lt;P&gt;2a.&amp;nbsp;&amp;nbsp; 03/02/2014. 234&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;second table looks like this&lt;/P&gt;&lt;P&gt;id.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Seq no&lt;/P&gt;&lt;P&gt;1a.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/01//2014.&amp;nbsp; 122&lt;/P&gt;&lt;P&gt;1a.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/01/2014.&amp;nbsp;&amp;nbsp; 121&lt;/P&gt;&lt;P&gt;1a.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/04/2014&amp;nbsp;&amp;nbsp; 124&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2a.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/02/2014.&amp;nbsp;&amp;nbsp;&amp;nbsp; 235&lt;/P&gt;&lt;P&gt;2a.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/01/2014.&amp;nbsp;&amp;nbsp; 233&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2a.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/01/2014.&amp;nbsp;&amp;nbsp; 232&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what I need is to match from the first sequence # to the one before from the 2nd table for example I would need from 1a&amp;nbsp; is seq 122 and for 2a i would need seq 233... Thanks for your assistance &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Mar 2014 01:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145181#M38566</guid>
      <dc:creator>BETO</dc:creator>
      <dc:date>2014-03-16T01:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain the 1st sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145182#M38567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This seems to work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data a;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input id $ DateA :mmddyy10. SeqA;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;format dateA yymmdd10.;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1a. 03/01/2014 123&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2a. 03/02/2014 234&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data b;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input id $ DateB :mmddyy10. SeqB;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;format dateB yymmdd10.;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1a. 03/01/2014&amp;nbsp; 122&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1a. 03/01/2014&amp;nbsp; 121&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1a. 03/04/2014&amp;nbsp; 124&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2a. 03/02/2014&amp;nbsp; 235&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2a. 03/01/2014&amp;nbsp; 233&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2a. 03/01/2014&amp;nbsp; 232&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=a; by id descending seqA; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=b; by id descending seqB; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data match;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do until(last.id);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; merge a b(in=inb); by id;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; if inb and seqB &amp;lt; seqA and not done then do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; done = 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;drop done;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Mar 2014 02:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145182#M38567</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-03-16T02:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain the 1st sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145183#M38568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PROC SQL APPROACH，raw data stolen from PG&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;input id $ DateA :mmddyy10. SeqA;&lt;/P&gt;&lt;P&gt;format dateA yymmdd10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1a. 03/01/2014 123&lt;/P&gt;&lt;P&gt;2a. 03/02/2014 234&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data b;&lt;/P&gt;&lt;P&gt;input id $ DateB :mmddyy10. SeqB;&lt;/P&gt;&lt;P&gt;format dateB yymmdd10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1a. 03/01/2014&amp;nbsp; 122&lt;/P&gt;&lt;P&gt;1a. 03/01/2014&amp;nbsp; 121&lt;/P&gt;&lt;P&gt;1a. 03/04/2014&amp;nbsp; 124&lt;/P&gt;&lt;P&gt;2a. 03/02/2014&amp;nbsp; 235&lt;/P&gt;&lt;P&gt;2a. 03/01/2014&amp;nbsp; 233&lt;/P&gt;&lt;P&gt;2a. 03/01/2014&amp;nbsp; 232&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE WANT AS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT A.ID, DATEA, (SELECT MAX(SEQB) FROM B WHERE A.ID=B.ID AND B.SEQB &amp;lt; A.SEQA GROUP BY B.ID) AS SEQ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; FROM A;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Mar 2014 02:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145183#M38568</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-03-16T02:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain the 1st sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145184#M38569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds like you want the MAX(seqno) that is less than the value from the other table.&amp;nbsp; Is that what mean by FIRST?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Mar 2014 03:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-obtain-the-1st-sequence-number/m-p/145184#M38569</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-16T03:38:30Z</dc:date>
    </item>
  </channel>
</rss>

