<?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: Changing the date format in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864535#M38198</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am not sure, I tried using input but that also didn't worked. I added the below step in my code but still does not work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;Start_trace = input(01JAN2022, yyddmm8.);
&amp;amp;End_trace = input(31DEC2022, yyddmm8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are using the wrong informat there.&amp;nbsp; YYMMDD informat wants strings that are&lt;A href="https://www.edubuzz.org/wbp45/2010/11/16/ononmatopoeia-words-that-imitate-the-sound-of-the/" target="_self"&gt; literally in YearMonthDay&lt;/A&gt; order.&lt;/P&gt;
&lt;P&gt;There is no YYDDMM informat because nobody uses date strings in YearDayMonth order.&amp;nbsp;&amp;nbsp;Your strings are something that the DATE informat will recognize.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the string is something the DATE informat will recognize then you can use it to make a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1ugvn0mocff92n13mw9s56300jv.htm#n10bbl1njzm9nrn1peo15mqcu551" target="_self"&gt;date constant&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_trace = "01JAN2022"d ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you create the macro variable from data don't bother to apply the DATE format to the value so that the macro variable just has a digit string that represents the number of days since 1960 that is actually used to store a date in a SAS variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2023 14:24:46 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-03-16T14:24:46Z</dc:date>
    <item>
      <title>Changing the date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864488#M38191</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a written a code where the tx_date is in DATETIME22.3 (21NOV2006:00:00:00.000) format and I have set Start_trace and End Trace in libraries which is in DATE9. (15MAR2022) format. In my code, I am getting error the date format is not equal. So I used the Datepart function but still shows the same error. Can you please suggest how to convert the date in the same pattern?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
create table Trace_Stamped as 
	select distinct debt_code,
DATEPART(tx_date) format date9. as tx_date
from p2scflow.debt_trans 
			where tran_code in ('MO9741','MO9742','MO9743','MO9744','MO9745','MO9746','MO9747','MO9748') 
and tx_date &amp;gt;= &amp;amp;Start_trace  and
              tx_date &amp;lt;= &amp;amp;End_Trace 	;
run; 

Error log:
30         proc sql;
31         create table Trace_Stamped as
32         	select distinct debt_code,
33         
34         					DATEPART(tx_date) format date9. as tx_date
35         					
36         		from p2scflow.debt_trans
37         			where tran_code in ('MO9741','MO9742','MO9743','MO9744','MO9745','MO9746','MO9747','MO9748')
38         				and tx_date &amp;gt;= &amp;amp;Start_trace  and
39                       tx_date &amp;lt;= &amp;amp;End_Trace
40         			  	
41         ;
ERROR: Expression using greater than or equal (&amp;gt;=) has components that are of different data types.
NOTE: The IN referred to may have been transformed from an OR to an IN at some point during PROC SQL WHERE clause optimization.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
42         run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2023 11:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864488#M38191</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-03-16T11:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864491#M38192</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a written a code where the tx_date is in DATETIME22.3 (21NOV2006:00:00:00.000) format and I have set Start_trace and End Trace in libraries which is in DATE9. (15MAR2022) format. In my code, I am getting error the date format is not equal.&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are getting an error that has components "of different data types" -- in other words, you are trying to compare numeric to character, and you can't do this. This has nothing to do with formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We do not know, so please tell us, what an actual value of tx_date is, and what the actual value of &amp;amp;start_trace is. We also need to know, from PROC CONTENTS or otherwise, whether tx_date is numeric or character.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 12:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864491#M38192</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-16T12:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864495#M38193</link>
      <description>&lt;P&gt;I am pulling tx_date from debt_trans table and tx_date is numeric. Start_trace I have just used in the library like&amp;nbsp;%let start_Trace = 01JAN2022;&amp;nbsp;&lt;BR /&gt;%let End_Trace = %sysfunc(today(),date9.);&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 12:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864495#M38193</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-03-16T12:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864500#M38194</link>
      <description>&lt;P&gt;You cannot compare a NUMERIC value, such a in tx_date, with a string such as 01JAN2022, which is neither a valid numeric value (it has letters in it). It is not a character string (not surrounded by quotes or double-quotes), and you can't compare a number to character string anyway. So SAS will not perform this comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I pose a question to you ... you can compare a number to a number, how can you turn the string 01JAN2022 into a number that will represent 01JAN2022??&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 12:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864500#M38194</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-16T12:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864514#M38195</link>
      <description>&lt;P&gt;I am not sure, I tried using input but that also didn't worked. I added the below step in my code but still does not work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;Start_trace = input(01JAN2022, yyddmm8.);
&amp;amp;End_trace = input(31DEC2022, yyddmm8.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2023 13:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864514#M38195</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-03-16T13:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864535#M38198</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am not sure, I tried using input but that also didn't worked. I added the below step in my code but still does not work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;Start_trace = input(01JAN2022, yyddmm8.);
&amp;amp;End_trace = input(31DEC2022, yyddmm8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are using the wrong informat there.&amp;nbsp; YYMMDD informat wants strings that are&lt;A href="https://www.edubuzz.org/wbp45/2010/11/16/ononmatopoeia-words-that-imitate-the-sound-of-the/" target="_self"&gt; literally in YearMonthDay&lt;/A&gt; order.&lt;/P&gt;
&lt;P&gt;There is no YYDDMM informat because nobody uses date strings in YearDayMonth order.&amp;nbsp;&amp;nbsp;Your strings are something that the DATE informat will recognize.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the string is something the DATE informat will recognize then you can use it to make a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1ugvn0mocff92n13mw9s56300jv.htm#n10bbl1njzm9nrn1peo15mqcu551" target="_self"&gt;date constant&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_trace = "01JAN2022"d ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you create the macro variable from data don't bother to apply the DATE format to the value so that the macro variable just has a digit string that represents the number of days since 1960 that is actually used to store a date in a SAS variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 14:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864535#M38198</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-16T14:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the date format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864537#M38199</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am not sure, I tried using input but that also didn't worked. I added the below step in my code but still does not work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;Start_trace = input(01JAN2022, yyddmm8.);
&amp;amp;End_trace = input(31DEC2022, yyddmm8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The above code should produce syntax errors, and can't possibly work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part of the problem is that you are trying to write macro code, when you have NOT created working SAS code without macros and without macro variables. That should always be the first step. When you have gotten the code to work properly without macros and without macro variables, then you should have much less difficulty turning the code into macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So instead of this part of your PROC SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;and tx_date &amp;gt;= &amp;amp;Start_trace &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can you write this without a macro variable to compare tx_date to be greater than or equal to something which represents 01JAN2022? You really ought to be able to do this without macro variables and get that to work first.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 13:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Changing-the-date-format/m-p/864537#M38199</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-16T13:52:45Z</dc:date>
    </item>
  </channel>
</rss>

