<?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: Comparing rows within a table based on ID and create a flag in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703003#M215363</link>
    <description>&lt;P&gt;Anyways, this should do it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.sample;
INPUT termid prevtermid id $;
DATALINES;
201508 201501 U100
201601 201508 U100
201608 201601 U100
201701 201608 U100
201705 201701 U100
201708 201701 U100
201508 201501 U200
201608 201601 U200
201701 201608 U200
201705 201701 U200
201708 201701 U200
201508 201501 U300
201601 201508 U300
201701 201608 U300
201705 201701 U300
201708 201701 U300
;

proc sort data = sample;
   by id termid;
run;

data want;

   dcl hash h ();
   h.definekey('termid');
   h.definedone();

   do until (last.id);
      set sample;
      by id;
      if first.id then RetainFlag = 'New';
      else if h.check(key : prevtermid) = 0 then RetainFlag = 'Yes';
      else RetainFlag = 'No';
      h.ref();
      output;
   end;

   h.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;termid  prevtermid  id    RetainFlag 
201508  201501      U100  New 
201601  201508      U100  Yes 
201608  201601      U100  Yes 
201701  201608      U100  Yes 
201705  201701      U100  Yes 
201708  201701      U100  Yes 
201508  201501      U200  New 
201608  201601      U200  No 
201701  201608      U200  Yes 
201705  201701      U200  Yes 
201708  201701      U200  Yes 
201508  201501      U300  New 
201601  201508      U300  Yes 
201701  201608      U300  No 
201705  201701      U300  Yes 
201708  201701      U300  Yes &lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Dec 2020 08:07:14 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-12-02T08:07:14Z</dc:date>
    <item>
      <title>Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/702994#M215357</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have following dataset (contains three different Ids) for students.&amp;nbsp; &amp;nbsp;I want to find out if they are retained or not based on if their record exists in the previous term.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA work.sample;&lt;BR /&gt;format id termid prevtermid;&lt;BR /&gt;&lt;BR /&gt;INPUT termid prevtermid id $;&lt;BR /&gt;DATALINES;&lt;BR /&gt;201508 201501 U100&lt;BR /&gt;201601 201508 U100&lt;BR /&gt;201608 201601 U100&lt;BR /&gt;201701 201608 U100&lt;BR /&gt;201705 201701 U100&lt;BR /&gt;201708 201701 U100&lt;/P&gt;&lt;P&gt;201508 201501 U200&lt;BR /&gt;201608 201601 U200&lt;BR /&gt;201701 201608 U200&lt;BR /&gt;201705 201701 U200&lt;BR /&gt;201708 201701 U200&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;201508 201501 U300&lt;BR /&gt;201601 201508 U300&lt;BR /&gt;201701 201608 U300&lt;BR /&gt;201705 201701 U300&lt;BR /&gt;201708 201701 U300&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;proc sort data=work.sample;&lt;BR /&gt;by id termid ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the sorted dataset will look like below:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; Termid&amp;nbsp; &amp;nbsp; &amp;nbsp;prevtermid&lt;/P&gt;&lt;P&gt;U100&amp;nbsp; &amp;nbsp;201508&amp;nbsp; &amp;nbsp; 201501&lt;BR /&gt;U100&amp;nbsp; &amp;nbsp;201601&amp;nbsp; &amp;nbsp; 201508&lt;BR /&gt;U100&amp;nbsp; &amp;nbsp;201608&amp;nbsp; &amp;nbsp; 201601&lt;BR /&gt;U100&amp;nbsp; &amp;nbsp;201701&amp;nbsp; &amp;nbsp; 201608&lt;BR /&gt;U100&amp;nbsp; &amp;nbsp;201705&amp;nbsp; &amp;nbsp; 201701&lt;BR /&gt;U100&amp;nbsp; &amp;nbsp;201708&amp;nbsp; &amp;nbsp; 201701&lt;BR /&gt;U200&amp;nbsp; &amp;nbsp;201508&amp;nbsp; &amp;nbsp; 201501&lt;BR /&gt;U200&amp;nbsp; &amp;nbsp;201608&amp;nbsp; &amp;nbsp; 201601&lt;BR /&gt;U200&amp;nbsp; &amp;nbsp;201701&amp;nbsp; &amp;nbsp;201608&lt;BR /&gt;U200&amp;nbsp; &amp;nbsp;201705&amp;nbsp; &amp;nbsp;201701&lt;BR /&gt;U200&amp;nbsp; &amp;nbsp;201708&amp;nbsp; &amp;nbsp;201701&lt;BR /&gt;U300&amp;nbsp; &amp;nbsp;201508&amp;nbsp; &amp;nbsp;201501&lt;BR /&gt;U300&amp;nbsp; &amp;nbsp;201601&amp;nbsp; &amp;nbsp;201508&lt;BR /&gt;U300&amp;nbsp; &amp;nbsp;201701&amp;nbsp; &amp;nbsp;201608&lt;BR /&gt;U300&amp;nbsp; &amp;nbsp;201705&amp;nbsp; &amp;nbsp; 201701&lt;BR /&gt;U300&amp;nbsp; &amp;nbsp;201708&amp;nbsp; &amp;nbsp;201701&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If for the same ID, prevTermID exists as a Termid in the previous rows, then I want to create a RetainFlag as Yes otherwise No. In the second iteration, if it is beginning of new Id (which will always have the "retainFlag = "no"), I want to mark this row as "New" to identify it as new student record.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the output should look like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;UID&amp;nbsp; &amp;nbsp; Termid&amp;nbsp; prevtermid&amp;nbsp; &amp;nbsp;RetainFlag&lt;/P&gt;&lt;P&gt;U100 201508 201501&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; New&lt;BR /&gt;U100 201601 201508&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes&lt;BR /&gt;U100 201608 201601&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes&lt;BR /&gt;U100 201701 201608&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Yes&lt;BR /&gt;U100 201705 201701&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;BR /&gt;U100 201708 201701&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Yes&lt;BR /&gt;U200 201508 201501&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; New&lt;BR /&gt;U200 201608 201601&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;No&lt;BR /&gt;U200 201701 201608&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Yes&lt;BR /&gt;U200 201705 201701&amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;BR /&gt;U200 201708 201701&amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;BR /&gt;U300 201508 201501&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;New&lt;BR /&gt;U300 201601 201508&amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;BR /&gt;U300 201701 201608&amp;nbsp; &amp;nbsp; &amp;nbsp;No&lt;BR /&gt;U300 201705 201701&amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;BR /&gt;U300 201708 201701&amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use Lag and retain but am not being successful how to accomplish it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will really appreciate your help.&amp;nbsp; Thank you so much for your time and willingness to share your expertise.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 07:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/702994#M215357</guid>
      <dc:creator>Sangita1</dc:creator>
      <dc:date>2020-12-02T07:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/702997#M215359</link>
      <description>&lt;P&gt;So in reality, you only have ID and termID, right? The variable&amp;nbsp;&lt;SPAN&gt;prevtermid is a variable you created yourself?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 07:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/702997#M215359</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-02T07:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703003#M215363</link>
      <description>&lt;P&gt;Anyways, this should do it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.sample;
INPUT termid prevtermid id $;
DATALINES;
201508 201501 U100
201601 201508 U100
201608 201601 U100
201701 201608 U100
201705 201701 U100
201708 201701 U100
201508 201501 U200
201608 201601 U200
201701 201608 U200
201705 201701 U200
201708 201701 U200
201508 201501 U300
201601 201508 U300
201701 201608 U300
201705 201701 U300
201708 201701 U300
;

proc sort data = sample;
   by id termid;
run;

data want;

   dcl hash h ();
   h.definekey('termid');
   h.definedone();

   do until (last.id);
      set sample;
      by id;
      if first.id then RetainFlag = 'New';
      else if h.check(key : prevtermid) = 0 then RetainFlag = 'Yes';
      else RetainFlag = 'No';
      h.ref();
      output;
   end;

   h.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;termid  prevtermid  id    RetainFlag 
201508  201501      U100  New 
201601  201508      U100  Yes 
201608  201601      U100  Yes 
201701  201608      U100  Yes 
201705  201701      U100  Yes 
201708  201701      U100  Yes 
201508  201501      U200  New 
201608  201601      U200  No 
201701  201608      U200  Yes 
201705  201701      U200  Yes 
201708  201701      U200  Yes 
201508  201501      U300  New 
201601  201508      U300  Yes 
201701  201608      U300  No 
201705  201701      U300  Yes 
201708  201701      U300  Yes &lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703003#M215363</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-02T08:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703009#M215368</link>
      <description>&lt;P&gt;Same technique (hash), slightly different code structure:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sample;
by id;
if _N_ = 1
then do;
  declare hash look ();
  look.definekey("termid");
  look.definedone();
end;
if first.id
then do;
  retainflag = "new";
  rc = look.clear();
end;
else do;
  if look.check(key:prevtermid) = 0
  then retainflag = "yes";
  else retainflag = "no";
end;
rc = look.add();
drop rc;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703009#M215368</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-02T08:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703013#M215371</link>
      <description>&lt;P&gt;When I write the following code:&lt;/P&gt;&lt;P&gt;It does not work properly because for the Fall term, I have the previous termid as the Spring term (which can be two rows above as some students take summer term and some do not take summer term).&amp;nbsp; So I have to do something when it is summer term, as that can set the lag variable incorrectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA work.identified;&lt;BR /&gt;set work.sample;&lt;BR /&gt;by ID;&lt;BR /&gt;retain lagtermid;&lt;BR /&gt;if first.id then X= 'New';&lt;BR /&gt;if prevtermid = lagtermid then retain_Student = 'Yes'; else retain_Student = 'No';&lt;BR /&gt;lagtermid = termid;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703013#M215371</guid>
      <dc:creator>Sangita1</dc:creator>
      <dc:date>2020-12-02T08:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703015#M215373</link>
      <description>&lt;P&gt;Did you take a look at the replies above?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703015#M215373</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-02T08:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703034#M215385</link>
      <description>&lt;P&gt;yes, I am new to programming, so I created the prevtermid column. Then I somehow was able to work it out by&lt;/P&gt;&lt;P&gt;DATA work.identified;&lt;BR /&gt;set work.sample;&lt;BR /&gt;by ID;&lt;BR /&gt;retain lagtermid;&lt;BR /&gt;if first.id then new_student= 'New';&lt;BR /&gt;y = lagtermid;&lt;BR /&gt;if prevtermid = lagtermid then retain_Student = 'Yes'; else retain_Student = 'No';&lt;BR /&gt;lagtermid = termid;&lt;BR /&gt;If Substr (termid, 5, 2) = '05' then lagtermid = prevtermid;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;I was going to drop all the extra columns - this is call "running around the block to walk one step".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your elegant code.&amp;nbsp; I am also going to read up the functions that you have used. Appreciate the super fast response.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703034#M215385</guid>
      <dc:creator>Sangita1</dc:creator>
      <dc:date>2020-12-02T08:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703036#M215387</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Your code is working great also, but I think I can only accept one example as solution. I will spend time learning definekey, definedone and how elegantly you have written the solution. I really appreciate your help. Thank you very much for sharing your knowledge with the newbees like me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 09:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703036#M215387</guid>
      <dc:creator>Sangita1</dc:creator>
      <dc:date>2020-12-02T09:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703038#M215388</link>
      <description>&lt;P&gt;Yes, I did. Both solutions are great. Now I have the code, and I am going to read the function calls so I know how/where to use them in future. Thankful for the help, as I was struggling for couple hours and reading how to use retain/lag. You made my day (or rather morning as it is very early morning for me).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 09:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703038#M215388</guid>
      <dc:creator>Sangita1</dc:creator>
      <dc:date>2020-12-02T09:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703041#M215390</link>
      <description>&lt;P&gt;The HASH object is a relatively new addition to the DATA step language, but it has proven itself to be a very powerful tool that enables rather simple solutions to seemingly complex issues, and can (and WILL) speed up processes by moving the sorting to a pure in-memory process when doing lookups.&lt;/P&gt;
&lt;P&gt;In the meantime, I have shaved&amp;nbsp;&lt;EM&gt;hours&lt;/EM&gt; of runtime from our existing programs by replacing sort/merge lookups with hash lookups wherever feasible (there&amp;nbsp;&lt;EM&gt;are&lt;/EM&gt; datasets that simply won't fit into available memory).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding coding styles:&lt;/P&gt;
&lt;P&gt;Everyone develops their own method of writing code, you can see two different styles between&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;and me. Both have their merits, the common ground is that we use consistent indentation for logical blocks, make use of whitespace (blanks) to easier identify words (keywords, variable names etc), and try to not pack too much into a single line, as that makes the code easier to read and easier to edit. Just an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set incoming (in=inc where=(xx1="Y") rename=(x1=xx1 x2=xx2) keep=x1 x2 x3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;compare to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set incoming (
  in=inc
  keep=x1 x2 x3
  rename=(
    x1=xx1
    x2=xx2
  )
  where=(xx1="Y")
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the second example, it is much easier to move a code element somewhere else by simply grabbing a complete line.&lt;/P&gt;
&lt;P&gt;And the order of the options follows the logical sequence in which the data step compiler will process them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When working in teams, the team members should develop and follow a single coding style.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 09:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703041#M215390</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-02T09:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703054#M215399</link>
      <description>Hi, I have one more question please. When I run the code on my big dataset, I am getting the type mismatch error&lt;BR /&gt;ERROR: Type mismatch for key variable TERMID at line 68 column 6.&lt;BR /&gt;I think it is because TERMID is a char. I am not sure if I should do a length statement or convert it (as some posts suggested). What might be the best way to resolve this? Thank you.</description>
      <pubDate>Wed, 02 Dec 2020 10:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703054#M215399</guid>
      <dc:creator>Sangita1</dc:creator>
      <dc:date>2020-12-02T10:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703057#M215401</link>
      <description>&lt;P&gt;Are both TermID and PrevTermID character?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Also, post your log please.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 10:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703057#M215401</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-02T10:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703058#M215402</link>
      <description>&lt;P&gt;Actually, I was able to fix that error. Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 10:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703058#M215402</guid>
      <dc:creator>Sangita1</dc:creator>
      <dc:date>2020-12-02T10:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing rows within a table based on ID and create a flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703068#M215403</link>
      <description>&lt;P&gt;Both variables must be of the same type, that's a given. Also, since these are date-related values, they should be stored as such:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
format id $8 termid prevtermid yymmn6.;
input (termid prevtermid) (:yymmn6.) id $;
datalines;
201508 201501 U100
201601 201508 U100
201608 201601 U100
201701 201608 U100
201705 201701 U100
201708 201701 U100
201508 201501 U200
201608 201601 U200
201701 201608 U200
201705 201701 U200
201708 201701 U200
201508 201501 U300
201601 201508 U300
201701 201608 U300
201705 201701 U300
201708 201701 U300
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Dec 2020 11:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-rows-within-a-table-based-on-ID-and-create-a-flag/m-p/703068#M215403</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-02T11:06:28Z</dc:date>
    </item>
  </channel>
</rss>

