<?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: Select max from multiple columns in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105724#M29479</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you PaigeMiller.&lt;/P&gt;&lt;P&gt;I need the output to be a dataset with all of the columns, not just some statistics.&amp;nbsp; &lt;BR /&gt;Can proc means or proc summary select the max value from each column and output the entire dataset in its original layout?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Feb 2013 19:55:58 GMT</pubDate>
    <dc:creator>KevinC_</dc:creator>
    <dc:date>2013-02-11T19:55:58Z</dc:date>
    <item>
      <title>Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105720#M29475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV id="post_message_6581679"&gt;Hello Everyone,&lt;P&gt;&lt;/P&gt;I have a table that contains hundreds of columns with duplicate unique keys (customer ID). I would like to get rid of the duplicates by selecting the row that contains the max values in a number of columns. For each customer, I would like to keep the row that has the max value in date1, date2, date3, date4, date5,.... etc.&lt;P&gt;&lt;/P&gt;The tricky part is there are hundreds of dates I need to check. Is there an efficient way to do this?&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;Here is a sample record:&lt;BR /&gt;cust_id date1 date2 date3 date4 date5 date6 date7 date8 ... date300&lt;BR /&gt;11111 2/2 3/3 4/4 5/5 6/6 7/7 8/8 9/9 .... 12/12&lt;BR /&gt;11111 2/1 3/1 4/1 5/1 6/1 7/1 8/1 9/1 .... 12/01&lt;P&gt;&lt;/P&gt;I would like to keep the first row since it has the max value in every column.&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;Any input will be greatly appreciated !&lt;BR /&gt;Thank you&amp;nbsp; &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;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 18:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105720#M29475</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2013-02-11T18:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105721#M29476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the fact that a row has a maximum value for one column implies that it has the maximum value for all columns..... then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data tmp;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;maxval=max(of date1-date300);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort in=tmp out=tmp2;&lt;/P&gt;&lt;P&gt;by cust_id descending maxval;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort in=tmp2 out=want nodupkey;&lt;/P&gt;&lt;P&gt;by cust_id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 19:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105721#M29476</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-02-11T19:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105722#M29477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you DBailey.&lt;/P&gt;&lt;P&gt;Unfortunately that is not the case.&amp;nbsp; You brought up a good point.&amp;nbsp; Now I think about it, this is more like the real data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cust_id date1 date2 date3 date4 date5 date6 date7 date8 ... date300&lt;/P&gt;&lt;P&gt;11111 2/2 3/3 4/1 5/5 6/6 7/1 8/8 9/9 .... 12/12&lt;/P&gt;&lt;P&gt;11111 2/1 3/1 &lt;STRONG&gt;4/9&lt;/STRONG&gt; 5/1 6/1 &lt;STRONG&gt;7/9&lt;/STRONG&gt; 8/1 9/1 .... 12/01&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&amp;nbsp; 4/9 and 7/9.&amp;nbsp; What i really need to do is to select the max value from each column.&amp;nbsp; So the ideal output would be:&lt;/P&gt;&lt;P&gt;11111 2/2 3/3 4/9 5/5 6/6 7/9 8/8 9/9 .... 12/12&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 19:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105722#M29477</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2013-02-11T19:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105723#M29478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Proc Means or Proc Summary with a BY statement should get you the max value for each cust_id&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 19:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105723#M29478</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-02-11T19:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105724#M29479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you PaigeMiller.&lt;/P&gt;&lt;P&gt;I need the output to be a dataset with all of the columns, not just some statistics.&amp;nbsp; &lt;BR /&gt;Can proc means or proc summary select the max value from each column and output the entire dataset in its original layout?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 19:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105724#M29479</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2013-02-11T19:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105725#M29480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, you'd have to combine the output data set from PROC MEANS or PROC SUMMARY with the original data. For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data combined;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge originaldata procmeansoutput;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by cust_id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 19:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105725#M29480</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-02-11T19:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105726#M29481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See this example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; t1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; id d1 d2 d3 d4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;111 2 4 6 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;222 4 5 6 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;111 3 2 5 8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;222 5 6 3 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;create&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; t2 &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max(d1) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; d1,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max(d2) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; d2,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max(d3) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; d3,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max(d4) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; d4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; t1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;order&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will give the output:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="1" style="background: lightgrey; padding: 5.25pt;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;111&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;4&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;6&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;8&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;222&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;5&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;6&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;6&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 5.25pt;" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif'; color: #002288; font-size: 12pt;"&gt;7&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will involve writing all your variable names in the proc sql step. There are ways to get those in SAS. However, you can also do that in Excel or Word.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 14:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105726#M29481</guid>
      <dc:creator>VD</dc:creator>
      <dc:date>2013-02-12T14:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105727#M29482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This logicworks for your problem, do that for other ids too:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here i have worked on 8 observations and you can change this number to 300 or whatever you require:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=================================================================================================&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;informat cust_id 5. date1 mmddyy10. date2 mmddyy10. date3 mmddyy10. date4 mmddyy10.&amp;nbsp; date5 mmddyy10.&amp;nbsp; date6 mmddyy10.&lt;/P&gt;&lt;P&gt;date7 mmddyy10.&amp;nbsp; date8 mmddyy10.;&lt;/P&gt;&lt;P&gt;input cust_id date1 date2 date3 date4&amp;nbsp; date5&amp;nbsp; date6&amp;nbsp; date7&amp;nbsp; date8 ;&lt;/P&gt;&lt;P&gt;format date1-date8 DATE9.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;11111 02/02/2012 03/03/2012 04/04/2012 5/5/2012 6/6/2011 7/7/2012 8/8/2010 9/9/2012 &lt;/P&gt;&lt;P&gt;11111 02/01/2009 03/01/2000 04/01/2013 5/1/2012 6/1/2012 7/1/2013 8/1/2012 9/1/2010 &lt;/P&gt;&lt;P&gt;;&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;proc print ;&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;%macro dset();&lt;/P&gt;&lt;P&gt;&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;drop table final;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to 8;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table final&amp;amp;i. as select distinct cust_id, max(date&amp;amp;i.) as dt&amp;amp;i. format date9. from new group by cust_id;&lt;/P&gt;&lt;P&gt;quit;&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;select dt&amp;amp;i. into: date&amp;amp;i. from final&amp;amp;i.;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;data final;&lt;/P&gt;&lt;P&gt;set final1-final%eval(&amp;amp;i.-1);&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;%do i=1 %to 8;&lt;/P&gt;&lt;P&gt;data final;&lt;/P&gt;&lt;P&gt;set final;&lt;/P&gt;&lt;P&gt;cst_id=cust_id;&lt;/P&gt;&lt;P&gt;date&amp;amp;i.="&amp;amp;&amp;amp;date&amp;amp;i.";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=final nodupkey;&lt;/P&gt;&lt;P&gt;by cst_id;&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;proc print data=final;&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;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%dset;&lt;/P&gt;&lt;P&gt;===============================================================================================================&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2013 05:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105727#M29482</guid>
      <dc:creator>damanaulakh88</dc:creator>
      <dc:date>2013-02-14T05:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select max from multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105728#M29483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is another approach, using Array():&lt;/P&gt;&lt;P&gt;if your data is already sorted or clustered by cust_id,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input cust_id (date1 date2 date3 date4 date5 date6 date7 date8) (:mmddyy10.);&lt;/P&gt;&lt;P&gt;format date1-date8 mmddyy10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;11111 02/02/2012 03/03/2012 04/04/2012 5/5/2012 6/6/2011 7/7/2012 8/8/2010 9/9/2012 &lt;/P&gt;&lt;P&gt;11111 02/01/2009 03/01/2000 04/01/2013 5/1/2012 6/1/2012 7/1/2013 8/1/2012 9/1/2010 &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;do until (last.cust_id);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by cust_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array h date1-date8;&lt;/P&gt;&lt;P&gt;array temp(8) _temporary_;&lt;/P&gt;&lt;P&gt;if first.cust_id then call missing(of temp(*));&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(h);&lt;/P&gt;&lt;P&gt;temp(i)=max(temp(i),h(i));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt; do i=1 to dim(h);&lt;/P&gt;&lt;P&gt;&amp;nbsp; h(i)=temp(i);&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2013 14:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-max-from-multiple-columns/m-p/105728#M29483</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-02-14T14:34:45Z</dc:date>
    </item>
  </channel>
</rss>

