<?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: Max value from all variables by subject ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325994#M72552</link>
    <description>there are 2 separate data sets first wee need to set or merge. and I want&lt;BR /&gt;it in sql&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
    <pubDate>Thu, 19 Jan 2017 15:12:04 GMT</pubDate>
    <dc:creator>SrikanthY</dc:creator>
    <dc:date>2017-01-19T15:12:04Z</dc:date>
    <item>
      <title>Max value from all variables by subject ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325988#M72549</link>
      <description>&lt;P&gt;I want Max mum date value per ID from 2 data sets from different variables.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13342i985F773C30AA9DF3/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Max date.PNG" title="Max date.PNG" /&gt;</description>
      <pubDate>Thu, 19 Jan 2017 14:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325988#M72549</guid>
      <dc:creator>SrikanthY</dc:creator>
      <dc:date>2017-01-19T14:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Max value from all variables by subject ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325992#M72550</link>
      <description>&lt;P&gt;Post test data in the form of a datastep. &amp;nbsp;At a guess something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array date{3};
  mdate=max(of date{*});
run;
proc sort data=want nodupkey;
  by id descending mdate;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jan 2017 15:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325992#M72550</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-19T15:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Max value from all variables by subject ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325994#M72552</link>
      <description>there are 2 separate data sets first wee need to set or merge. and I want&lt;BR /&gt;it in sql&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Thu, 19 Jan 2017 15:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325994#M72552</guid>
      <dc:creator>SrikanthY</dc:creator>
      <dc:date>2017-01-19T15:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Max value from all variables by subject ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325995#M72553</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you could consolidate all data in one table, and get the max date by ID from there, like this:&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table data3 as
select ID, max(date) as maxdate format=yymmdd10. from 
      (select ID, date1 as date from data1 union
       select ID, date2 as date from date2 union
       select ID, date3 as date from data2)
group by ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 15:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/325995#M72553</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-19T15:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Max value from all variables by subject ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/326002#M72556</link>
      <description>Thank you for your quick response. I got the exact o/p what I have expected.&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Thu, 19 Jan 2017 15:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/326002#M72556</guid>
      <dc:creator>SrikanthY</dc:creator>
      <dc:date>2017-01-19T15:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Max value from all variables by subject ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/326004#M72558</link>
      <description>&lt;P&gt;This is why it is a good idea to follow the guidance for posting questions which you will see when you post. &amp;nbsp;Provide clear test data (in the form of a datasteps) which show you problem, and full information about what needs to happen plus test output. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is there are requirement for SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your main problem here is that your data is transposed - this means the data goes across the table. &amp;nbsp;SQL is built specifically to work with&amp;nbsp;normalised data, i.e. data going down the table. &amp;nbsp;So, step one will be getting the data into a way that SQL can work with, if you have 3 dates then you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;select SUBJECT_ID,DATE1 as DATE from HAVE
union all 
select SUBJECT_ID,DATE2 as DATE from HAVE
union all
select SUBJECT_ID,DATE3 as DATE from HAVE&lt;/PRE&gt;
&lt;P&gt;From this, you can put it in a sub-query, then do max on that data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select   distinct SUBJECT_ID,
           DATE
  from   (&lt;BR /&gt;           select SUBJECT_ID,DATE1 as DATE from HAVE&lt;BR /&gt;           union all &lt;BR /&gt;           select SUBJECT_ID,DATE2 as DATE from HAVE&lt;BR /&gt;           union all&lt;BR /&gt;           select SUBJECT_ID,DATE3 as DATE from HAVE
         )
  group by SUBJECT_ID;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 15:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-value-from-all-variables-by-subject-ID/m-p/326004#M72558</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-19T15:23:13Z</dc:date>
    </item>
  </channel>
</rss>

