<?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: Questions Regarding Using a Where Statement with Dates and the &amp;quot;D&amp;quot; Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Questions-Regarding-Using-a-Where-Statement-with-Dates-and-the/m-p/823422#M325116</link>
    <description>&lt;P&gt;If you want to use a date constant the text inside the quotes has to be something the DATE &lt;STRONG&gt;informat&lt;/STRONG&gt; can read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where survey_date_num &amp;gt;= "12MAY2022"d;
where survey_date_num &amp;gt;= "12May2022"d;
where survey_date_num &amp;gt;= "12may2022"d;
where survey_date_num &amp;gt;= "12 MAY 2022"d;
where survey_date_num &amp;gt;= "12-MAY-2022"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The format attached to the variable in the dataset being read does not matter since a format is just instructions for how to &lt;STRONG&gt;display&lt;/STRONG&gt; the value as a string.&amp;nbsp; So what format you have attached to a variable has no impact on what value is actually stored in the variable.&amp;nbsp;&amp;nbsp;You could also just use the actual number of days, which for that date is the number&amp;nbsp;22777.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where survey_date_num &amp;gt;= 22777;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;1579  data check;
1580    date1= input('2022-05-12',yymmdd10.);
1581    date2 = "12MAY2022"d ;
1582    put date1= / date2= ;
1583  run;

date1=22777
date2=22777
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jul 2022 00:36:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-07-15T00:36:28Z</dc:date>
    <item>
      <title>Questions Regarding Using a Where Statement with Dates and the "D" Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-Regarding-Using-a-Where-Statement-with-Dates-and-the/m-p/823417#M325113</link>
      <description>&lt;P&gt;Hi! I have a data set where my dates are formatted as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;YYYY-MM-DD&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code that I used to convert my date data to the format above:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;data one_quality;
set one;
started_time_new=compress(substr(started_time,1,10));
received_on_new=compress(substr(received_on,1,10));
run;

data one_quality_new; 
set one_quality; 
started_time_num=input(started_time_new, anydtdte10.); 
received_on_num=input(received_on_new, anydtdte10.);
survey_date_num=input(survey_date,anydtdte10.); 
format started_time_num received_on_num survey_date_num YYMMDD10.; 
run; 

proc print data=one_quality_new; 
var started_time_num started_time_new received_on_new received_on_num 
survey_date survey_date_num; 
run; &lt;/PRE&gt;&lt;P&gt;Here is a sample of my print output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JackZ295_0-1657829189501.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73333iAB1814099189F2ED/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JackZ295_0-1657829189501.png" alt="JackZ295_0-1657829189501.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to filter my print results such that only dates (survey_date_num) after 2022-05-12 are printed. I wrote the below code in an attempt to achieve those results:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;title 'Print Out of One_Quality_New Data Set After 5/12/2022'; 
proc print data=one_quality_new; 
where survey_date_num &amp;gt;= "2022-05-12"d;
var survey_date_num household_name; 
run; &lt;/PRE&gt;&lt;P&gt;However, when I tried to run this code, I ran into the following errors:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR: Invalid date/time/datetime constant "2022-05-12"d.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR: Syntax error while parsing WHERE clause.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a reason why I am running into this error? Any input regarding this would be much appreciated! Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 20:11:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-Regarding-Using-a-Where-Statement-with-Dates-and-the/m-p/823417#M325113</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2022-07-14T20:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: Questions Regarding Using a Where Statement with Dates and the "D" Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-Regarding-Using-a-Where-Statement-with-Dates-and-the/m-p/823419#M325115</link>
      <description>&lt;P&gt;The date literals must be the DATE format appearance: "01JAN2022"d , or for those that live dangerously you can use 2-digit years. It doesn't matter what format your variable is the comparison uses literal values in the Date format with the D indicator.&lt;/P&gt;
&lt;P&gt;It simplifies code for development and helps understanding when reading someone else's code which date is meant. Wait til you try to decipher what date someone means when given "010203" and told that is a date.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 20:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-Regarding-Using-a-Where-Statement-with-Dates-and-the/m-p/823419#M325115</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-14T20:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Questions Regarding Using a Where Statement with Dates and the "D" Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-Regarding-Using-a-Where-Statement-with-Dates-and-the/m-p/823422#M325116</link>
      <description>&lt;P&gt;If you want to use a date constant the text inside the quotes has to be something the DATE &lt;STRONG&gt;informat&lt;/STRONG&gt; can read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where survey_date_num &amp;gt;= "12MAY2022"d;
where survey_date_num &amp;gt;= "12May2022"d;
where survey_date_num &amp;gt;= "12may2022"d;
where survey_date_num &amp;gt;= "12 MAY 2022"d;
where survey_date_num &amp;gt;= "12-MAY-2022"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The format attached to the variable in the dataset being read does not matter since a format is just instructions for how to &lt;STRONG&gt;display&lt;/STRONG&gt; the value as a string.&amp;nbsp; So what format you have attached to a variable has no impact on what value is actually stored in the variable.&amp;nbsp;&amp;nbsp;You could also just use the actual number of days, which for that date is the number&amp;nbsp;22777.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where survey_date_num &amp;gt;= 22777;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;1579  data check;
1580    date1= input('2022-05-12',yymmdd10.);
1581    date2 = "12MAY2022"d ;
1582    put date1= / date2= ;
1583  run;

date1=22777
date2=22777
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 00:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-Regarding-Using-a-Where-Statement-with-Dates-and-the/m-p/823422#M325116</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-15T00:36:28Z</dc:date>
    </item>
  </channel>
</rss>

