<?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: Data set's last. variable not working as intended? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545055#M150751</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=Orders;
by order_id descending update_date;
run;

proc sort data=Orders nodupkey;
by order_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 21 Mar 2019 21:10:57 GMT</pubDate>
    <dc:creator>sotojcr</dc:creator>
    <dc:date>2019-03-21T21:10:57Z</dc:date>
    <item>
      <title>Data set's last. variable not working as intended?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545044#M150745</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set full of orders.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set has 150+ columns and when I update it every day some duplicates will be introduced.&lt;/P&gt;&lt;P&gt;I need to remove those duplicates (based on order_id) and keep the record with the most recent update_date.&lt;/P&gt;&lt;P&gt;The following code works most of the time but I just noticed there are duplicates that the code for some reason is not removing and it does not make any sense.&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=Orders out=Orders;&lt;BR /&gt;by order_id update_date;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data Orders;&lt;BR /&gt;set Orders;&lt;BR /&gt;by order_id update_date;&lt;BR /&gt;if last.update_date;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I missing here and why is this working for some orders but not the others.&lt;/P&gt;&lt;P&gt;I've been staring at one particular order for the past 2hrs and it's the same exact order_id and the update_date is clearly different yet the code returns both records!?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 20:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545044#M150745</guid>
      <dc:creator>SasDewd</dc:creator>
      <dc:date>2019-03-21T20:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Data set's last. variable not working as intended?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545046#M150747</link>
      <description>&lt;P&gt;Your subsetting statement is incorrect:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if last.update_date;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if last.order_id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also notice, this is dangerous:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data orders;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set orders;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;...........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your logic is wrong, you can destroy your data set ORDERS.&amp;nbsp; Safer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data orders2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set orders;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;..............&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 21:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545046#M150747</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-21T21:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Data set's last. variable not working as intended?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545051#M150748</link>
      <description>&lt;P&gt;Hmm..OK...I will try that.&lt;/P&gt;&lt;P&gt;But why?&lt;/P&gt;&lt;P&gt;If I have 2 records:&lt;/P&gt;&lt;P&gt;Order_Id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Update_date&lt;/P&gt;&lt;P&gt;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2019&lt;/P&gt;&lt;P&gt;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2/1/2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want to keep the one from 2/1/2019 why would I say if &lt;SPAN&gt;&amp;nbsp;last.order_id and not&amp;nbsp;&amp;nbsp;last.update_date??&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Just trying to understand.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Second part makes perfect sense..I will change that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;!!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 21:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545051#M150748</guid>
      <dc:creator>SasDewd</dc:creator>
      <dc:date>2019-03-21T21:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: Data set's last. variable not working as intended?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545053#M150749</link>
      <description>&lt;P&gt;I forgot to mention...especially since the code I had was removing duplicates as I was hoping it would...just not all of them&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 21:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545053#M150749</guid>
      <dc:creator>SasDewd</dc:creator>
      <dc:date>2019-03-21T21:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Data set's last. variable not working as intended?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545055#M150751</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=Orders;
by order_id descending update_date;
run;

proc sort data=Orders nodupkey;
by order_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2019 21:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545055#M150751</guid>
      <dc:creator>sotojcr</dc:creator>
      <dc:date>2019-03-21T21:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Data set's last. variable not working as intended?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545065#M150753</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202675"&gt;@SasDewd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set full of orders.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data set has 150+ columns and when I update it every day some duplicates will be introduced.&lt;/P&gt;
&lt;P&gt;I need to remove those duplicates (based on order_id) and keep the record with the most recent update_date.&lt;/P&gt;
&lt;P&gt;The following code works most of the time but I just noticed there are duplicates that the code for some reason is not removing and it does not make any sense.&lt;/P&gt;
&lt;P&gt;Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=Orders out=Orders;&lt;BR /&gt;by order_id update_date;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data Orders;&lt;BR /&gt;set Orders;&lt;BR /&gt;by order_id update_date;&lt;BR /&gt;if last.update_date;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am I missing here and why is this working for some orders but not the others.&lt;/P&gt;
&lt;P&gt;I've been staring at one particular order for the past 2hrs and it's the same exact order_id and the update_date is clearly different yet the code returns both records!?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You may need to consider how you are "updating" you data. I sounds like you might be APPENDING data. Either with Proc Append or using a SET statement with two data sets, the master and the "new" data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a single record for ORDER_ID perhaps you need to use a data step UPDATE statement.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 21:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545065#M150753</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-21T21:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Data set's last. variable not working as intended?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545069#M150754</link>
      <description>LAST.ORDER_ID is true when you hit the last observation for an ORDER_ID.  Those are the observations you are looking for.&lt;BR /&gt;&lt;BR /&gt;LAST.UPDATE_DATE is true when you hit the last observation for an UPDATE_DATE.  That would select one observation per date.</description>
      <pubDate>Thu, 21 Mar 2019 21:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-s-last-variable-not-working-as-intended/m-p/545069#M150754</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-21T21:47:35Z</dc:date>
    </item>
  </channel>
</rss>

