<?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 which is earliest date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812947#M34070</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Data A:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; Date1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;&amp;nbsp;20180409&amp;nbsp; &amp;nbsp; &amp;nbsp;20150506&amp;nbsp; &amp;nbsp; &amp;nbsp; 20140203&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 20170607&amp;nbsp; &amp;nbsp; &amp;nbsp;20180607&amp;nbsp; &amp;nbsp; &amp;nbsp;20170607&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;20150809&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20150810&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TRT&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;20140203 ( I want the earliest date to be selected out of 3 dates)&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;20170607&amp;nbsp; ( I want earliest and more treatment dates)&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;20150809&amp;nbsp; ( earliest date selected)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I do this is SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 12 May 2022 13:11:36 GMT</pubDate>
    <dc:creator>Smitha9</dc:creator>
    <dc:date>2022-05-12T13:11:36Z</dc:date>
    <item>
      <title>which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812947#M34070</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Data A:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; Date1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;&amp;nbsp;20180409&amp;nbsp; &amp;nbsp; &amp;nbsp;20150506&amp;nbsp; &amp;nbsp; &amp;nbsp; 20140203&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 20170607&amp;nbsp; &amp;nbsp; &amp;nbsp;20180607&amp;nbsp; &amp;nbsp; &amp;nbsp;20170607&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;20150809&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20150810&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TRT&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;20140203 ( I want the earliest date to be selected out of 3 dates)&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;20170607&amp;nbsp; ( I want earliest and more treatment dates)&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;20150809&amp;nbsp; ( earliest date selected)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I do this is SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 13:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812947#M34070</guid>
      <dc:creator>Smitha9</dc:creator>
      <dc:date>2022-05-12T13:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812951#M34071</link>
      <description>&lt;P&gt;Are variables DATE1 DATE2 and DATE3 numeric or character? If numeric, what format has been applied? Please show us the PROC CONTENTS output for these variables.&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 13:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812951#M34071</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-12T13:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812961#M34072</link>
      <description>Selecting the earliest date in SAS?  Yes, it can be done in SAS.&lt;BR /&gt;How to do it? Sort the dates in ascending order. Dates have to be numeric.&lt;BR /&gt;</description>
      <pubDate>Thu, 12 May 2022 13:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812961#M34072</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-05-12T13:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812969#M34073</link>
      <description>numeric and format=20.</description>
      <pubDate>Thu, 12 May 2022 13:54:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812969#M34073</guid>
      <dc:creator>Smitha9</dc:creator>
      <dc:date>2022-05-12T13:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812970#M34074</link>
      <description>&lt;P&gt;Earlier dates are smaller than later dates.&amp;nbsp; So use the MIN(,) function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  trt = min(of date1-date3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your date variables are actual SAS date values (and just look like that in your printout because they are being displayed using the YYMMDDN8. format) then also attach a date type format to the new TRT variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that your example values do NOT look like dates to me.&amp;nbsp; &amp;nbsp;The look like integer numbers in the style YY,YYM,MDD.&amp;nbsp;But since the digits are in Year, Month, Day order they will still work with the MIN() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 13:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812970#M34074</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-12T13:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812972#M34075</link>
      <description>&lt;P&gt;Data posted in usable form helps us to provide tested code. So here a just some hints to find the solution yourself.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Thanks to missing dates, using min-function in a data step is not possible.&lt;/LI&gt;
&lt;LI&gt;proc transpose + proc summary will work, because summary ignores missing values by default.&lt;/LI&gt;
&lt;LI&gt;A data step with a loop seems to be a good idea, too.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 12 May 2022 13:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812972#M34075</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-05-12T13:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812978#M34076</link>
      <description>&lt;P&gt;Try this. Modify the output format as needed.&lt;BR /&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;.&amp;nbsp;Corrected as suggested.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data A;
Retain ID earliest_date Date1 Date2  Date3;
Informat date1 date2 date3 anydtdte8.;
Format earliest_date date1 date2 date3 date9. ;*yyyymmdd8n.;
infile datalines truncover;
input ID Date1 Date2  Date3;
earliest_date= min(of date1-date3);
datalines;
1 20180409 20150506 20140203
2 20170607 20180607 20170607
3 20150809      .   20150810
 ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output will be like this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1652365829363.png" style="width: 424px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71385iA7151953B363830A/image-dimensions/424x150?v=v2" width="424" height="150" role="button" title="Sajid01_0-1652365829363.png" alt="Sajid01_0-1652365829363.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 14:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812978#M34076</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-05-12T14:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812980#M34077</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;numeric and format=20.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which means you don't have dates, you have some numeric crap that looks like dates. And you have a suboptimal data structure (wide instead of long).&lt;/P&gt;
&lt;P&gt;First, transpose to long:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input ID Date1 Date2 Date3;
datalines;
1 20180409 20150506 20140203
2 20170607 20180607 20170607
3 20150809 . 20150810
;

proc transpose data=a out=long_bad (drop=_name_ rename=(col1=date) where=(date ne .));
by id;
var date:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Next, make usable dates out of the numeric crap:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long_good;
set long_bad;
date = input(put(date,z8.),yymmdd8.);
format date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, apply the proper procedure:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=long_good nway;
class id;
var date;
output out=want (drop=_type_ _freq_) min()=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 May 2022 14:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812980#M34077</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-12T14:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: which is earliest date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812982#M34078</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;earliest_date= min(date1-date3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you give the MIN() function only one value like that it just returns the input.&amp;nbsp; So that is the same as running:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;earliest_date= date1-date3 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will just be difference in days between the first and last date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use a variable list with a SAS function you need to add the OF keyword.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;earliest_date= min(of date1-date3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 14:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/which-is-earliest-date/m-p/812982#M34078</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-12T14:20:27Z</dc:date>
    </item>
  </channel>
</rss>

