<?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: Using proc SQL to keep obs based on multiple column criteria in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111138#M30804</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Welcome to the forum.&lt;/P&gt;&lt;P&gt;Below is a sample code.&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input account date mmddyy10.;&lt;/P&gt;&lt;P&gt;format date mmddyy10.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1001 10/23/2008&lt;/P&gt;&lt;P&gt;1001 10/28/2009&lt;/P&gt;&lt;P&gt;1005 09/19/2008&lt;/P&gt;&lt;P&gt;1006 08/08/2008&lt;/P&gt;&lt;P&gt;1006 09/09/2009&lt;/P&gt;&lt;P&gt;1006 10/10/2010&lt;/P&gt;&lt;P&gt;1007 12/12/2012&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 account,max(date) as max_date format=mmddyy10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by account;&lt;/P&gt;&lt;P&gt; quit;&lt;/P&gt;&lt;P&gt; proc print data=want;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 31 Dec 2012 14:57:12 GMT</pubDate>
    <dc:creator>Linlin</dc:creator>
    <dc:date>2012-12-31T14:57:12Z</dc:date>
    <item>
      <title>Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111136#M30802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have never used this forum before so just wanted to firstly introduce myself, but also apologise in case I have accidentally broken any forum rules or asked a question that has already been answered!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I am quite new to SAS and still in the learning beginner phase. Imagine for example I have a record set where I have account numbers that may or may not appear more than once, and a second column with Dates in. Using Proc SQL, (or any other method you see fit) how would I keep only account numbers with the maximum date for each account number? So for each unique account number in column a, keep only the record containing the highest date value in column b. My experience is mainly in VBA, so understanding a simple step like this might help me to come across to the syntax of SAS, as all I'm thinking about right now is some sort of For Each statement!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks in advance,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Dec 2012 14:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111136#M30802</guid>
      <dc:creator>Thoney</dc:creator>
      <dc:date>2012-12-31T14:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111137#M30803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Welcome to the Forum. This will create a new dataset of all records where the date is the latest date for an account number (it can be many records if the latest date appears more than once) :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table lastDates as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select *&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from myDataSet&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;group by actNumber&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;having date=max(date);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&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>Mon, 31 Dec 2012 14:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111137#M30803</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-12-31T14:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111138#M30804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Welcome to the forum.&lt;/P&gt;&lt;P&gt;Below is a sample code.&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input account date mmddyy10.;&lt;/P&gt;&lt;P&gt;format date mmddyy10.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1001 10/23/2008&lt;/P&gt;&lt;P&gt;1001 10/28/2009&lt;/P&gt;&lt;P&gt;1005 09/19/2008&lt;/P&gt;&lt;P&gt;1006 08/08/2008&lt;/P&gt;&lt;P&gt;1006 09/09/2009&lt;/P&gt;&lt;P&gt;1006 10/10/2010&lt;/P&gt;&lt;P&gt;1007 12/12/2012&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 account,max(date) as max_date format=mmddyy10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by account;&lt;/P&gt;&lt;P&gt; quit;&lt;/P&gt;&lt;P&gt; proc print data=want;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Dec 2012 14:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111138#M30804</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-12-31T14:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111139#M30805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;and here are a couple of non-sql ways to do what you want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat id $3.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat date date.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format date date.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input id date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;001 10jan2012&lt;/P&gt;&lt;P&gt;001 31dec2012&lt;/P&gt;&lt;P&gt;001 5mar2012&lt;/P&gt;&lt;P&gt;002 30dec2012&lt;/P&gt;&lt;P&gt;002 29dec2012&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*using most other methods*/&lt;/P&gt;&lt;P&gt;proc sort data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id descending date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*using sort after sorting*/&lt;/P&gt;&lt;P&gt;proc sort data=have out=want nodupkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*using datastep after sorting*/&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.id then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also do it using proc summary, using a hash in a datastep and probably a number of other ways I'm not thinking of at the moment.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Dec 2012 15:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111139#M30805</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-31T15:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111140#M30806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just wanted to thank you all for your swift responses, I have found exactly what I needed and several other ways of achieving the same goal! Very pleased!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Dec 2012 15:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111140#M30806</guid>
      <dc:creator>Thoney</dc:creator>
      <dc:date>2012-12-31T15:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111141#M30807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Art,&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Happy New Year to you&lt;/SPAN&gt;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;! How are you doing? Is it cold in your area? ours is about 20F(-5C) today.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Dec 2012 15:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111141#M30807</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-12-31T15:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111142#M30808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="3068" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;: Sounds like Boston and Toronto are going to be equally cold tonight.&amp;nbsp; Time to make good use of my fireplace.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Happy New Year to you too!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Dec 2012 15:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111142#M30808</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-31T15:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111143#M30809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Tom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're fairly new to SAS, you should check out a SAS product called Enterprise Guide. It provides a point and click interface that generates the SAS code, so you can use EG to obtain your result, and then see what SAS code was created to do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Dec 2012 16:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111143#M30809</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2012-12-31T16:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc SQL to keep obs based on multiple column criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111144#M30810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi Tom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is something that I asked one of my colleagues when I first started, however it appears that the company I work for are not renewing the part of the license that covers Enterprise. Therefore I've been told I will only be able to use raw SAS code, so must learn the "in at the deep end" way lol. Thanks for the suggestion though&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Dec 2012 16:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-proc-SQL-to-keep-obs-based-on-multiple-column-criteria/m-p/111144#M30810</guid>
      <dc:creator>Thoney</dc:creator>
      <dc:date>2012-12-31T16:12:11Z</dc:date>
    </item>
  </channel>
</rss>

