<?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: Dates comparison in sas in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/549595#M8702</link>
    <description>Thanks a lot for all your help&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;</description>
    <pubDate>Tue, 09 Apr 2019 13:43:59 GMT</pubDate>
    <dc:creator>Codepro</dc:creator>
    <dc:date>2019-04-09T13:43:59Z</dc:date>
    <item>
      <title>Dates comparison in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/546500#M8229</link>
      <description>&lt;P&gt;Hello pals,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a file in which i have Datex and date 1 ,date2,date3 and date4 columns and my requirements is to compare 'Datex' column with other 4 date columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If datex = 2019-01-01&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date1=2016-01=01&amp;nbsp; Date2=2019-01=01 Date3 = 2017-09-01&lt;/P&gt;&lt;P&gt;Date4 = 2018-11-01&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then my requirement is to check datex column value with all other date columns and then if any of these date values is less than 30 days or greater than 30 days or falls with this range ..then the date1 column should be That valid date which falls in these category ...in the above case date 2 column falls in these category and it should be in Date1 column..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks much in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 14:05:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/546500#M8229</guid>
      <dc:creator>Codepro</dc:creator>
      <dc:date>2019-03-27T14:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dates comparison in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/546502#M8230</link>
      <description>&lt;P&gt;Array processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input datex :yymmdd10. (date1-date4) (:yymmdd10.);
format datex date1-date4 yymmddd10.;
datalines;
2019-01-01 2016-01-01 2019-01-01 2017-09-01 2018-11-01
;
run;

data want;
set have;
array dates {*} date1-date4;
do i = 1 to dim(dates);
  if datex - 30 &amp;lt;= dates{i} &amp;lt;= datex + 30
  then do;
    date1 = dates{i};
    leave;
  end;
end;
drop i;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;     datex         date1         date2         date3         date4

2019-01-01    2019-01-01    2019-01-01    2017-09-01    2018-11-01
&lt;/PRE&gt;
&lt;P&gt;date1 has been replaced with the value of date2.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 14:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/546502#M8230</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-27T14:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dates comparison in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/546507#M8231</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your pseudo code&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268189"&gt;@Codepro&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If datex = 2019-01-01&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date1=2016-01=01&amp;nbsp; Date2=2019-01=01 Date3 = 2017-09-01&lt;/P&gt;
&lt;P&gt;Date4 = 2018-11-01&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Contains several errors. First date literals, or specific date values you are interested in are in the form of '01JAN2019'd. Second 2019-01-01 is not a valid value though SAS may do arithmetic with it yielding 2017. If your value is a character variable then the comparison would be datex='2019-01-01'; if it is supposed to be an actual SAS date value then datex='01JAN2019'd.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your if should have a "then do" to indicate the following statements are conditional.&lt;/P&gt;
&lt;P&gt;The statements in SAS must end in a ;&lt;/P&gt;
&lt;P&gt;You would also need an "end;" after the conditional assignments to end the block.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 14:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/546507#M8231</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-27T14:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dates comparison in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/549595#M8702</link>
      <description>Thanks a lot for all your help&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;</description>
      <pubDate>Tue, 09 Apr 2019 13:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dates-comparison-in-sas/m-p/549595#M8702</guid>
      <dc:creator>Codepro</dc:creator>
      <dc:date>2019-04-09T13:43:59Z</dc:date>
    </item>
  </channel>
</rss>

