<?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 Formatting date variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-variables/m-p/690024#M209838</link>
    <description>&lt;P&gt;I am trying to create a unique ID that is a combination of an ID variable and a date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In both datasets I have an ID variable which is a numeric variable with a length of 8 and format Best12. In one dataset I have delivery_date which is length 8, format MMDDYY10. and informat date9. In the other I have new_delivery_date which has the same characteristics.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am using is&lt;/P&gt;&lt;P&gt;ID2=put(ID, &lt;STRONG&gt;8.&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;del_date2=put(delivery_date, &lt;STRONG&gt;9.&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;Del_ID = strip(ID2)||strip(del_date2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID2=put(ID, &lt;STRONG&gt;8.&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;del_date2=put(new_del_date, &lt;STRONG&gt;9.&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;Del_ID = strip(ID2)||strip(del_date2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the del_ID for one patient in both datasets. Do you have any idea why the Del_IDs would not match in the datasets if the variables are all formatted the same way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset1:&lt;/P&gt;&lt;P&gt;ID 1001958&amp;nbsp; Del_ID&amp;nbsp;10019581903&lt;STRONG&gt;8&lt;/STRONG&gt;&amp;nbsp; new_del_date 02/15/2012&lt;/P&gt;&lt;P&gt;Dataset 2:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID 1001958&amp;nbsp; Del_ID&amp;nbsp;10019581903&lt;STRONG&gt;9&lt;/STRONG&gt;&amp;nbsp; new_del_date 02/15/2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why does one Del_ID end in 8 and the other in 9 if the dates are formated the same way?&lt;/P&gt;</description>
    <pubDate>Thu, 08 Oct 2020 14:53:24 GMT</pubDate>
    <dc:creator>GAL1986</dc:creator>
    <dc:date>2020-10-08T14:53:24Z</dc:date>
    <item>
      <title>Formatting date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-variables/m-p/690024#M209838</link>
      <description>&lt;P&gt;I am trying to create a unique ID that is a combination of an ID variable and a date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In both datasets I have an ID variable which is a numeric variable with a length of 8 and format Best12. In one dataset I have delivery_date which is length 8, format MMDDYY10. and informat date9. In the other I have new_delivery_date which has the same characteristics.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am using is&lt;/P&gt;&lt;P&gt;ID2=put(ID, &lt;STRONG&gt;8.&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;del_date2=put(delivery_date, &lt;STRONG&gt;9.&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;Del_ID = strip(ID2)||strip(del_date2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID2=put(ID, &lt;STRONG&gt;8.&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;del_date2=put(new_del_date, &lt;STRONG&gt;9.&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;Del_ID = strip(ID2)||strip(del_date2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the del_ID for one patient in both datasets. Do you have any idea why the Del_IDs would not match in the datasets if the variables are all formatted the same way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset1:&lt;/P&gt;&lt;P&gt;ID 1001958&amp;nbsp; Del_ID&amp;nbsp;10019581903&lt;STRONG&gt;8&lt;/STRONG&gt;&amp;nbsp; new_del_date 02/15/2012&lt;/P&gt;&lt;P&gt;Dataset 2:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID 1001958&amp;nbsp; Del_ID&amp;nbsp;10019581903&lt;STRONG&gt;9&lt;/STRONG&gt;&amp;nbsp; new_del_date 02/15/2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why does one Del_ID end in 8 and the other in 9 if the dates are formated the same way?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 14:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-date-variables/m-p/690024#M209838</guid>
      <dc:creator>GAL1986</dc:creator>
      <dc:date>2020-10-08T14:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-variables/m-p/690033#M209842</link>
      <description>&lt;P&gt;SAS stores dates as the number of days.&amp;nbsp; All numeric variables in SAS are floating point values. The date formats (like MMDDYY , DDMMYY, YYMMDD, DATE, etc) will only use the integer part of the value.&lt;/P&gt;
&lt;P&gt;But 9. format you used to convert the number of days to an digit string will round instead.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data test;
2      today=today()+0.6;
3      put today= +1 today date9. +1 today 9. ;
4    run;

today=22196.6  08OCT2020     22197&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the goal is to make a string of digits that represents ID and DELIVERY_DATE then you should use leading zeros in the ID value to force it to always use the same number of digits. To represent dates in strings use Y-M-D order so that the strings will sort properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length DEL_ID $16;
DEL_ID = put(id,Z8.) || put(delivery_date,yymmdd8.);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Oct 2020 15:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-date-variables/m-p/690033#M209842</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-08T15:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-variables/m-p/690049#M209849</link>
      <description>Thank you! I will try this today!&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Oct 2020 15:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-date-variables/m-p/690049#M209849</guid>
      <dc:creator>GAL1986</dc:creator>
      <dc:date>2020-10-08T15:28:13Z</dc:date>
    </item>
  </channel>
</rss>

