<?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: Compare two dates in a PROC SQL statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593103#M170152</link>
    <description>&lt;P&gt;Don't format the macro variable. Just leave it as the numeric value of the date: &lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;inputn&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;date1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the formatted value you would have to use "&amp;amp;datefin."d for the comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or instead of bothering to convert yymmdd format text use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; date1 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; "31DEC2018"d&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;and use:&amp;nbsp; date_table&amp;nbsp;le &amp;amp;date1. &lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 16:32:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-10-01T16:32:22Z</dc:date>
    <item>
      <title>Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593096#M170147</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with dates stocked in a DATE9 format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to set a macro variable to extract data from a specific date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To convert my date, I use the following code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date1 = 2018-12-31;
%let datefin = %sysfunc(inputn(&amp;amp;date1, yymmdd10.), date9.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I write %put &amp;amp;datefin.; it works and shows 31DEC2018.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I try to extract datas with a PROC SQL, I got an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code I'm trying to run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date1 = 2018-12-31;
%let datefin = %sysfunc(inputn(&amp;amp;date1, yymmdd10.), date9.);

PROC SQL;
CREATE TABLE TEST AS
(SELECT *
FROM TABLESOURCE
WHERE DATE_TABLE &amp;lt;= &amp;amp;DATEFIN.);
QUIT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the part of the log showing an error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;35&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31DEC2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ___________&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-322 : Syntax error, expecting of the following: !, !!, &amp;amp;,........&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas where I am doing something wrong? Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 17:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593096#M170147</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-01T17:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593098#M170148</link>
      <description>&lt;P&gt;Wouldn't you need&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token string"&gt;"&amp;amp;DATEFIN."&lt;/SPAN&gt;d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

PROC SQL;

CREATE TABLE TEST AS

(SELECT *

FROM TABLESOURCE

WHERE DATE_TABLE &amp;lt;= "&amp;amp;DATEFIN."d);

QUIT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593098#M170148</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-01T16:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593100#M170149</link>
      <description>You need quotes around the macro variable when it resolves and a d. Or don't apply a format to it when doing the %SYSFUNC() and it will work fine.</description>
      <pubDate>Tue, 01 Oct 2019 16:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593100#M170149</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-01T16:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593102#M170151</link>
      <description>First, thanks for the quick reply. I tried what you proposed and it doesn't seem to work, since the output dataset is empty. &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593102#M170151</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-01T16:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593103#M170152</link>
      <description>&lt;P&gt;Don't format the macro variable. Just leave it as the numeric value of the date: &lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;inputn&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;date1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the formatted value you would have to use "&amp;amp;datefin."d for the comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or instead of bothering to convert yymmdd format text use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; date1 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; "31DEC2018"d&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;and use:&amp;nbsp; date_table&amp;nbsp;le &amp;amp;date1. &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593103#M170152</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-01T16:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593104#M170153</link>
      <description>Show your work please. I'm certain those approaches will work.</description>
      <pubDate>Tue, 01 Oct 2019 16:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593104#M170153</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-01T16:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593105#M170154</link>
      <description>&lt;P&gt;I tried both of your solutions (@Reeza and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;) and it doesn't work either. I don't understand why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way that SAS is displaying the date in date9 format but in fact it could be coded in international format (YYYY-MM-DD) ? Is there a way to check this?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593105#M170154</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-01T16:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593106#M170155</link>
      <description>1. Is that all your code shown? If you're using SQL Pass through for example, the rules are different. &lt;BR /&gt;2. Show what you tried, because otherwise this should work and if it's not it's likely because of something we don't know.</description>
      <pubDate>Tue, 01 Oct 2019 16:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593106#M170155</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-01T16:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593110#M170157</link>
      <description>&lt;P&gt;The code in my first post is exactly what I have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datefin = "31DEC2018"d;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and in the code I used :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE TEST1 AS
( SELECT *
FROM TABLESOURCE
WHERE DATETABLE le &amp;amp;datefin.
);
QUIT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Still do not works. It's annoying because I try simple things and maybe it's just me :S&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593110#M170157</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-01T16:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593117#M170159</link>
      <description>What is the format and type of datetable variable?&lt;BR /&gt;Usually before you create a macro you make working code. What works without any macro variables? First figure that out and then convert it to a macro.&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593117#M170159</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-01T16:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593119#M170160</link>
      <description>&lt;P&gt;I would recommend&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token statement"&gt;%let date1=31dec2019;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and inside your program just use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token statement"&gt;WHERE&lt;/SPAN&gt; DATE_TABLE &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; "&amp;amp;date1"d ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a macro ready-made for date-literal usage, you have no need for %sysfunc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593119#M170160</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-01T16:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593120#M170161</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;2018&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-21&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-31&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not a valid date as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593120#M170161</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-01T16:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593122#M170163</link>
      <description>&lt;P&gt;Does&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE TEST1 AS
SELECT *
FROM TABLESOURCE
WHERE DATETABLE le "31DEC2018"d;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;work?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593122#M170163</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-10-01T16:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593123#M170164</link>
      <description>&lt;P&gt;Examples of both approaches - both work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date1 = 2005-12-01;
%let datefin = %sysfunc(inputn(&amp;amp;date1., yymmdd10.));

proc sql;
create table test1 as
select * 
from sashelp.stocks
where date = &amp;amp;datefin;
quit;


%let date1 = 2005-12-01;
%let datefin = %sysfunc(inputn(&amp;amp;date1, yymmdd10.), date9.);

%put &amp;amp;datefin;

proc sql;
create table test2 as
select * 
from sashelp.stocks
where date = "&amp;amp;datefin."d;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/285961"&gt;@jpprovost&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The code in my first post is exactly what I have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datefin = "31DEC2018"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and in the code I used :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE TEST1 AS
( SELECT *
FROM TABLESOURCE
WHERE DATETABLE le &amp;amp;datefin.
);
QUIT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Still do not works. It's annoying because I try simple things and maybe it's just me :S&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593123#M170164</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-01T16:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593134#M170166</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/285961"&gt;@jpprovost&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The code in my first post is exactly what I have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datefin = "31DEC2018"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and in the code I used :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE TEST1 AS
( SELECT *
FROM TABLESOURCE
WHERE DATETABLE le &amp;amp;datefin.
);
QUIT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Still do not works. It's annoying because I try simple things and maybe it's just me :S&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What does that mean?&amp;nbsp; Show the log.&amp;nbsp; Did you get an error or wrong number of observations?&lt;/P&gt;
&lt;P&gt;Is DATETABLE really a DATE value?&amp;nbsp; Perhaps it is a DATETIME value?&amp;nbsp; If it is a DATETIME value then unless it is before 6AM on January 1, 1960 then its value is probably greater than any DATE value you might compare it to.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where DATETABLE le "31DEC2018:00:00"dt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where datepart(DATETABLE) le &amp;amp;datefin.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 17:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593134#M170166</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-01T17:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593135#M170167</link>
      <description>&lt;P&gt;I fix the typo, thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 17:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593135#M170167</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-01T17:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593140#M170171</link>
      <description>&lt;P&gt;The type is DATE and the format is DATE9.&lt;/P&gt;&lt;P&gt;I really think that the DATE9 format is not liked by PROC SQL... Is there a way to diagnose this out?&lt;/P&gt;&lt;P&gt;I don't know where I can make an error.&lt;/P&gt;&lt;P&gt;The dataset contains a DATE value in DATE9 format.&lt;/P&gt;&lt;P&gt;I use a criteria which is exactly in a DATE9 format.&lt;/P&gt;&lt;P&gt;I compare those two together and it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will continue seeking for a solution.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 17:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593140#M170171</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-01T17:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593144#M170173</link>
      <description>&lt;P&gt;Still do not works. I think we have a problem with the field in our dataset.&lt;/P&gt;&lt;P&gt;I will try other thing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 17:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593144#M170173</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-01T17:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593146#M170174</link>
      <description>&lt;P&gt;It doesn't matter to SQL (or any SAS DATA step or proc) what the format of a date variable is, because the internal numeric value of the variable is the same regardless of format.&amp;nbsp;&amp;nbsp; You problem is apparently how to use a macrovar to express a date literal value for use in PROC SQL.&amp;nbsp; That is why I recommend:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let date1=31DEC2018;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql ....;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; ... where date_table &amp;lt;="&amp;amp;date1"d;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 17:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593146#M170174</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-01T17:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two dates in a PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593147#M170175</link>
      <description>&lt;P&gt;Maxim 3: Know Your Data.&lt;/P&gt;
&lt;P&gt;Run proc contents on tablesource and look at the type and format of date_table. From that you can infer its content.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 17:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-dates-in-a-PROC-SQL-statement/m-p/593147#M170175</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-01T17:40:19Z</dc:date>
    </item>
  </channel>
</rss>

