<?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: Convert Text Date in a Proc SQL Where in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949763#M371491</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/468800"&gt;@Rebecca_K&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello!&amp;nbsp; Still fairly new to SAS and having a hard time with text/date conversions.&amp;nbsp; I have a Text formatted date (coming from a table that has text formatted column) and want to compare it to an actual date.&amp;nbsp; Here's a sample mock-up that would help solve what I'm trying to do.&amp;nbsp; Although it "runs" it doesn't actually filter the data to just the two dates that meet the requirement.&amp;nbsp; &amp;nbsp;(Member 2222 and 3333 should show, 1111 should be excluded)&amp;nbsp; The "CheckDate" below needs to be in the MM/DD/YYYY format unfortunately.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;DATA HAVE;
INPUT MEMBERID : $20. DOB : MMDDYY10.;
Format DOB MMDDYY10.;
CARDS;
1111 1/12/2001
1222 2/11/2003
3333 3/11/2003
;
run;

%let &lt;FONT size="5" color="#FF00FF"&gt;&lt;STRONG&gt;CheckDate&lt;/STRONG&gt;&lt;/FONT&gt; = 2/2/2002;

Proc sql;
  select * from Have 
  where DOB &amp;gt; &lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt;&amp;amp;CheckDate_new.&lt;/STRONG&gt;&lt;/FONT&gt;
;quit;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; Any help is appreciated!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First would be to use one name for the macro variable. Your code would, as far as I can see, been using an undefined macro variable, which means blank and should be throwing errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compare date values to date values. The input function with the appropriate informat is the typical tool. But the INPUT function expects a text value so would need quotes:&lt;/P&gt;
&lt;PRE&gt;%let CheckDate = 2/2/2002;

Proc sql;
  select * from Have 
  where DOB &amp;gt; input("&amp;amp;CheckDate.",mmddyy10.)
;quit;&lt;/PRE&gt;
&lt;P&gt;Which with your example data yields:&lt;/P&gt;
&lt;DIV class="branch"&gt;&lt;A target="_blank" name="IDX22"&gt;&lt;/A&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" cellspacing="0" cellpadding="3"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l m header" scope="col"&gt;MEMBERID&lt;/TH&gt;
&lt;TH class="r m header" scope="col"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DOB&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;1222&lt;/TD&gt;
&lt;TD class="r data"&gt;02/11/2003&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3333&lt;/TD&gt;
&lt;TD class="r data"&gt;03/11/2003&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;OR&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;Supply the value in the manner that SAS expects date literals to by used: Quotes around a value in Date9. or Date7 appearance:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;Proc sql;
  select * from Have 
  where DOB &amp;gt; "02FEB2002"D
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="4"&gt;The only time to worry about the Format of a value in comparisons is when you explicitly apply the format to the value for comparison. And since Put would be the method and creates character values any of the "less than" or "greater than" comparisons will almost always be a poor result unless the format is a YYMMDD order &lt;STRONG&gt;AND&lt;/STRONG&gt; you make sure either both or no character values have the leading zeroes for month and day.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;If you must use a macro variable at all I would go with something more like:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;%let CheckDate = 02FEB2002;

Proc sql;
  select * from Have 
  where DOB &amp;gt; "&amp;amp;CheckDate."D
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="4"&gt;because regardless of the macro variable name a structure like "&amp;amp;macrovar"D should tell a moderately experienced program the value should 1) be a date and 2) looks like ddMONyyy or ddMONyy&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Nov 2024 21:58:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-11-01T21:58:39Z</dc:date>
    <item>
      <title>Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949749#M371478</link>
      <description>&lt;P&gt;Hello!&amp;nbsp; Still fairly new to SAS and having a hard time with text/date conversions.&amp;nbsp; I have a Text formatted date (coming from a table that has text formatted column) and want to compare it to an actual date.&amp;nbsp; Here's a sample mock-up that would help solve what I'm trying to do.&amp;nbsp; Although it "runs" it doesn't actually filter the data to just the two dates that meet the requirement.&amp;nbsp; &amp;nbsp;(Member 2222 and 3333 should show, 1111 should be excluded)&amp;nbsp; The "CheckDate" below needs to be in the MM/DD/YYYY format unfortunately.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA HAVE;
INPUT MEMBERID : $20. DOB : MMDDYY10.;
Format DOB MMDDYY10.;
CARDS;
1111 1/12/2001
1222 2/11/2003
3333 3/11/2003
;
run;

%let CheckDate = 2/2/2002;

Proc sql;
  select * from Have 
  where DOB &amp;gt; &amp;amp;CheckDate_new.
;quit;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 19:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949749#M371478</guid>
      <dc:creator>Rebecca_K</dc:creator>
      <dc:date>2024-11-01T19:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949750#M371479</link>
      <description>&lt;P&gt;Not sure I understand your description, so let's just examine your CODE and explain what you did wrong there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You created a NUMERIC variable named DOB with DATE values.&amp;nbsp; You attached the MMDDYY format with a display width of 10 characters to it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You then created a macro variable with the string 2/2/2002 and used it to generate a SAS statement that will look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where DOB &amp;gt; 2/2/2002&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So to the SAS language that is comparing the numbers in the DOB variable to the number that results from dividing 2 by 2 and then again by 2002.&amp;nbsp; Will be something less than 1.&amp;nbsp; Since the way SAS stores dates is by the number of days since 01JAN1960 you are asking for any DOB that is after 01JAN1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead you wanted to look for date values larger then February second of 2002 you would wnat to generate a SAS statement like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where DOB &amp;gt; '02FEB2002'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So either set your macro variable to have that string:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CheckDate = '02FEB2002'd ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or set it to the actual number that SAS uses to represent that date.&amp;nbsp; Which is 15,373 :&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      check = '02FEB2002'd ;
3      put check= / check= comma. / check=mmddyy10. / check=date9.;
4    run;

check=15373
check=15,373
check=02/02/2002
check=02FEB2002
&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Nov 2024 20:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949750#M371479</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-01T20:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949751#M371480</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CheckDate = 2/2/2002;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;checkdate is a text string with slashes in it, not a date. Dates cannot be equal to text strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make a macro variables that has the proper values to compare to a date value, here are two methods&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Method 1 -- The MDY Function */
%let checkdate = %sysfunc(mdy(2,2,2002));
/* Method 2 -- Use a date literal inside %SYSEVALF */
%let dt=%sysevalf('02FEB2002'd);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In Method 2, the date literal '02FEB2002'd must be in exactly that form (except FEB can be lower case), inside quotes and followed by the letter d. There are in reality a lot more than these two methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your PROC SQL also has an error, there is no macro variable named &amp;amp;checkdate_new&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 20:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949751#M371480</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-01T20:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949754#M371483</link>
      <description>&lt;P&gt;Make it a SAS date value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CheckDate = %sysfunc(mdy(2,2,2002));

proc sql;
  select * from have 
  where DOB &amp;gt; &amp;amp;CheckDate.
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Nov 2024 20:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949754#M371483</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-01T20:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949755#M371484</link>
      <description>&lt;P&gt;Thanks, all, sorry my description wasn't clear.&amp;nbsp; Unfortunately, the&amp;nbsp;CheckDate is coming from a table that has a TEXT format, and the dates will be in the "mm/dd/yyyy" format, so I won't be able to change it.&amp;nbsp; What i can change is the WHERE clause&amp;nbsp; (sorry, had "new" in there, edited it out)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;where DOB &amp;gt; &amp;amp;CheckDate.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can i cast one or the other variable to the same type, to make them compatible to each other for the compare?&amp;nbsp; Thanks so much for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 20:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949755#M371484</guid>
      <dc:creator>Rebecca_K</dc:creator>
      <dc:date>2024-11-01T20:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949759#M371488</link>
      <description>&lt;P&gt;So you don't create the macro variable with a %LET, but in some other way from a dataset? Please show your real code.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 20:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949759#M371488</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-01T20:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949760#M371489</link>
      <description>&lt;P&gt;So you are saying you have a text string such as '02/02/2002' in a SAS data set, and you have to work with that? Am I understanding the situation properly now? So assume the variable in the data set is named DATE, with the text string value of '02/02/2002'. This little bit of creates macro variable CHECKDATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    set yourdataset;
    call symputx('checkdate',input(date,ddmmyy10.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 20:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949760#M371489</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-01T20:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949761#M371490</link>
      <description>&lt;P&gt;If you have strings in the MM/DD/YYYY style then you can use the MMDDYY INFORMAT to convert them into actual date values.&amp;nbsp; So assuming the macro variable CHECKDATE has a valid SAS date value (as previously discussed) then just convert the string into a date for comparison.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where input(DOB,mmddyy10.) &amp;gt; &amp;amp;CheckDate.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note:&amp;nbsp; If you had stored the date strings in YMD order then you could have compared them directly since the character string would sort into chronological order.&amp;nbsp; Assuming they all used the same delimiter and have two digits for month and day and four digits for year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could do something like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where DOB &amp;gt; "2002/02/02"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It addition to the sorting issue note that using date strings in YMD order will prevent users from confusing December Tenth for October Twelfth.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 21:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949761#M371490</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-01T21:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949763#M371491</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/468800"&gt;@Rebecca_K&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello!&amp;nbsp; Still fairly new to SAS and having a hard time with text/date conversions.&amp;nbsp; I have a Text formatted date (coming from a table that has text formatted column) and want to compare it to an actual date.&amp;nbsp; Here's a sample mock-up that would help solve what I'm trying to do.&amp;nbsp; Although it "runs" it doesn't actually filter the data to just the two dates that meet the requirement.&amp;nbsp; &amp;nbsp;(Member 2222 and 3333 should show, 1111 should be excluded)&amp;nbsp; The "CheckDate" below needs to be in the MM/DD/YYYY format unfortunately.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;DATA HAVE;
INPUT MEMBERID : $20. DOB : MMDDYY10.;
Format DOB MMDDYY10.;
CARDS;
1111 1/12/2001
1222 2/11/2003
3333 3/11/2003
;
run;

%let &lt;FONT size="5" color="#FF00FF"&gt;&lt;STRONG&gt;CheckDate&lt;/STRONG&gt;&lt;/FONT&gt; = 2/2/2002;

Proc sql;
  select * from Have 
  where DOB &amp;gt; &lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt;&amp;amp;CheckDate_new.&lt;/STRONG&gt;&lt;/FONT&gt;
;quit;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; Any help is appreciated!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First would be to use one name for the macro variable. Your code would, as far as I can see, been using an undefined macro variable, which means blank and should be throwing errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compare date values to date values. The input function with the appropriate informat is the typical tool. But the INPUT function expects a text value so would need quotes:&lt;/P&gt;
&lt;PRE&gt;%let CheckDate = 2/2/2002;

Proc sql;
  select * from Have 
  where DOB &amp;gt; input("&amp;amp;CheckDate.",mmddyy10.)
;quit;&lt;/PRE&gt;
&lt;P&gt;Which with your example data yields:&lt;/P&gt;
&lt;DIV class="branch"&gt;&lt;A target="_blank" name="IDX22"&gt;&lt;/A&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" cellspacing="0" cellpadding="3"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l m header" scope="col"&gt;MEMBERID&lt;/TH&gt;
&lt;TH class="r m header" scope="col"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DOB&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;1222&lt;/TD&gt;
&lt;TD class="r data"&gt;02/11/2003&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3333&lt;/TD&gt;
&lt;TD class="r data"&gt;03/11/2003&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;OR&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;Supply the value in the manner that SAS expects date literals to by used: Quotes around a value in Date9. or Date7 appearance:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;Proc sql;
  select * from Have 
  where DOB &amp;gt; "02FEB2002"D
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="4"&gt;The only time to worry about the Format of a value in comparisons is when you explicitly apply the format to the value for comparison. And since Put would be the method and creates character values any of the "less than" or "greater than" comparisons will almost always be a poor result unless the format is a YYMMDD order &lt;STRONG&gt;AND&lt;/STRONG&gt; you make sure either both or no character values have the leading zeroes for month and day.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;If you must use a macro variable at all I would go with something more like:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;%let CheckDate = 02FEB2002;

Proc sql;
  select * from Have 
  where DOB &amp;gt; "&amp;amp;CheckDate."D
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="4"&gt;because regardless of the macro variable name a structure like "&amp;amp;macrovar"D should tell a moderately experienced program the value should 1) be a date and 2) looks like ddMONyyy or ddMONyy&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 21:58:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949763#M371491</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-11-01T21:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Text Date in a Proc SQL Where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949992#M371539</link>
      <description>&lt;P&gt;If I understand your second post correctly, what you have is not a SAS DATE numeric variable (as shown in your first post), but a text variable in the format "mm/dd/yyyy". If that is the case, you will have to convert the character values to SAS dates in the actual WHERE clause, something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CheckDate = '01FEB2002'd;

Proc sql;
  select * from Have 
  where input(DOB,mmddyy10.) &amp;gt; &amp;amp;CheckDate
;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Nov 2024 03:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Text-Date-in-a-Proc-SQL-Where/m-p/949992#M371539</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2024-11-06T03:37:41Z</dc:date>
    </item>
  </channel>
</rss>

