<?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: How to denote date in a readable format? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803226#M316277</link>
    <description>&lt;P&gt;Run Proc Contents on your source data set and show us the results for the variable Ordering_date, as in type and assigned format. One strongly suspects that your variable is not actually date if you are asking with that code.&lt;/P&gt;
&lt;P&gt;The actual format applied to a variable has nothing to do with the results of comparisons or calculations though using character values to compare to numeric values has issues with conversion attempts and/or failures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does your LOG show any invalid data message such as the following code generates:&lt;/P&gt;
&lt;PRE&gt;data junk;
   /* x is not a date, but a character value*/
   x = '12/15/2021';
   /* y converts the string to a date*/
   y = input(x,mmddyy10.);
   format y mmddyy10.;
   a = x &amp;lt; '15JAN2022'd;
   b = y &amp;lt; '15Jan2022'd;
run;&lt;/PRE&gt;
&lt;P&gt;Which when run has the log show:&lt;/P&gt;
&lt;PRE&gt;
84   data junk;
85      /* x is not a date, but a character value*/
86      x = '12/15/2021';
87      /* y converts the string to a date*/
88      y = input(x,mmddyy10.);
89      format y mmddyy10.;
90      a = x &amp;lt; '15JAN2022'd;
91      b = y &amp;lt; '15Jan2022'd;
92   run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      90:8
NOTE: Invalid numeric data, x='12/15/2021' , at line 90 column 8.
x=12/15/2021 y=12/15/2021 a=1 b=1 _ERROR_=1 _N_=1
NOTE: The data set WORK.JUNK has 1 observations and 4 variables.
&lt;/PRE&gt;
&lt;P&gt;The note about character conversion and invalid data are both created when X is a character value pretending to be a SAS date value, which is numeric. So X tries to be converted to a number, which will use the BEST12. informat and fails because that informat cannot handle / characters.&lt;/P&gt;</description>
    <pubDate>Mon, 21 Mar 2022 20:43:19 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-03-21T20:43:19Z</dc:date>
    <item>
      <title>How to denote date in a readable format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803219#M316273</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69653i44A8C73A6CC9EB0D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I attached a picture of the code. I am trying to create a new variable "INT" according to the range of date in "ORDERING_DATE". The SAS data that this line of data step is reading has "ORDERING_DATE" in mm/dd/yyyy format. What should I change the date (i.e&amp;nbsp;'01MAR2019'D) to, in order for SAS data step to read the date and create the INT variable correctly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 19:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803219#M316273</guid>
      <dc:creator>tongxu</dc:creator>
      <dc:date>2022-03-21T19:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to denote date in a readable format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803224#M316275</link>
      <description>&lt;P&gt;If&amp;nbsp;&lt;SPAN&gt;ORDERING_DATE has been successfully created as a SAS date then your code looks fine to me. Why do you think it is not working correctly?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 20:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803224#M316275</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-03-21T20:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to denote date in a readable format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803225#M316276</link>
      <description>&lt;P&gt;Are you sure that the variable ORDERING_DATE is a SAS date? Or, what is the error message in the log?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 20:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803225#M316276</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2022-03-21T20:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to denote date in a readable format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803226#M316277</link>
      <description>&lt;P&gt;Run Proc Contents on your source data set and show us the results for the variable Ordering_date, as in type and assigned format. One strongly suspects that your variable is not actually date if you are asking with that code.&lt;/P&gt;
&lt;P&gt;The actual format applied to a variable has nothing to do with the results of comparisons or calculations though using character values to compare to numeric values has issues with conversion attempts and/or failures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does your LOG show any invalid data message such as the following code generates:&lt;/P&gt;
&lt;PRE&gt;data junk;
   /* x is not a date, but a character value*/
   x = '12/15/2021';
   /* y converts the string to a date*/
   y = input(x,mmddyy10.);
   format y mmddyy10.;
   a = x &amp;lt; '15JAN2022'd;
   b = y &amp;lt; '15Jan2022'd;
run;&lt;/PRE&gt;
&lt;P&gt;Which when run has the log show:&lt;/P&gt;
&lt;PRE&gt;
84   data junk;
85      /* x is not a date, but a character value*/
86      x = '12/15/2021';
87      /* y converts the string to a date*/
88      y = input(x,mmddyy10.);
89      format y mmddyy10.;
90      a = x &amp;lt; '15JAN2022'd;
91      b = y &amp;lt; '15Jan2022'd;
92   run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      90:8
NOTE: Invalid numeric data, x='12/15/2021' , at line 90 column 8.
x=12/15/2021 y=12/15/2021 a=1 b=1 _ERROR_=1 _N_=1
NOTE: The data set WORK.JUNK has 1 observations and 4 variables.
&lt;/PRE&gt;
&lt;P&gt;The note about character conversion and invalid data are both created when X is a character value pretending to be a SAS date value, which is numeric. So X tries to be converted to a number, which will use the BEST12. informat and fails because that informat cannot handle / characters.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 20:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803226#M316277</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-21T20:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to denote date in a readable format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803229#M316278</link>
      <description>All of the INT values are 0. I spot checked, and many should be 1 or 2, because the dates are within the condition boundaries listed. I imported the dataset from excel, and that file has ORDERING_DATE in mm/dd/yyyy format. The code in the picture is someone else's code that I'm taking over, I think he must've converted the excel values for that variable into for example 03MAR2021 format. So that his code is as pictured. I am not planning to convert the excel file into 03MAR2021 format. But this code pictured does not read it correctly. If I can write something that can make it read mm/dd/yyyy, that'd solve the problem.</description>
      <pubDate>Mon, 21 Mar 2022 21:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803229#M316278</guid>
      <dc:creator>tongxu</dc:creator>
      <dc:date>2022-03-21T21:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to denote date in a readable format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803239#M316282</link>
      <description>&lt;P&gt;A FORMAT in SAS is just instructions for how to print the values as text.&amp;nbsp; It does not change the values.&lt;/P&gt;
&lt;P&gt;SAS has two types of variables, fixed length character strings and floating point numbers.&amp;nbsp; DATE values are stored as numbers.&amp;nbsp; You can then attach any date format you want to have the date values display in the style you prefer.&amp;nbsp; But when entering a date literal, like in the code you posted the photograph of, you must use a string that the DATE informat can convert to a date value.&amp;nbsp; The format attached to the variable does not matter because it does not impact the value the variable has, just how it looks when you print it as text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variable is character instead of numeric you will need to use the INPUT() function to convert the character strings into date values.&amp;nbsp; If the character strings look like dates in the M-D-Y order you mentioned then use the MMDDYY10. informat to convert them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variable is actually a DATETIME value instead of a DATE value then you will need to use the DATEPART() function to convert the datetime value (number of seconds) Into a date value (number of days) before you can compare it to the date literals in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 23:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803239#M316282</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-21T23:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to denote date in a readable format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803260#M316289</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/337920"&gt;@tongxu&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Your code appears fine. It is possible that the ordering_date may be a string. In that case it needs to be converted to date format.&lt;BR /&gt;I am giving an example in which the date the ordering date is a date number. I have also taken another variable where the date value is stored as a string. In both cases you will get identical results. The code is self explanatory and should help solving the issue. Please let me know if there are questions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let d1='01MAR2022'd;
%let d2='10MAR2022'd;
%let d2='20MAR2022'd;
data one;
informat ordering_date_nmbr date9.;
format ordering_date_nmbr date9.;
length ordering_date_str $ 10;
input ordering_date_nmbr  ordering_date_str ;
 if ordering_date_nmbr &amp;lt; &amp;amp;d1. then INT=0;
else if &amp;amp;d1.&amp;lt;= ordering_date_nmbr &amp;lt;= &amp;amp;d2. then INT=1;
else INT=2;
 if input(ordering_date_str,date9.) &amp;lt; &amp;amp;d1. then INT2=0;
else if &amp;amp;d1.&amp;lt;= input(ordering_date_str,date9.)  &amp;lt;= &amp;amp;d2. then INT2=1;
else INT2=2;
datalines;
01MAR2022 01MAR2022
10FEB2022 10FEB2022
10MAR2022 10MAR2022
21MAR2022 21MAR2022
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output will be like as follows. The INT and INT2 values are identical.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1647913407394.png" style="width: 492px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69666i60E275E62C84E1F2/image-dimensions/492x198?v=v2" width="492" height="198" role="button" title="Sajid01_0-1647913407394.png" alt="Sajid01_0-1647913407394.png" /&gt;&lt;/span&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 01:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803260#M316289</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-03-22T01:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to denote date in a readable format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803274#M316291</link>
      <description>&lt;P&gt;Please post the complete log of your step by copy/pasting it into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 06:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-denote-date-in-a-readable-format/m-p/803274#M316291</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-22T06:12:35Z</dc:date>
    </item>
  </channel>
</rss>

