<?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 Best way to handle multple date formats in one variable [data cleaning] in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Best-way-to-handle-multple-date-formats-in-one-variable-data/m-p/651876#M24149</link>
    <description>&lt;P&gt;I have a variable "date"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In most instances the date is reported as "YYYYMMDD" but in some instances the day is missing, so I only have "YYYYMM"&lt;/P&gt;&lt;P&gt;I ultimately want a date variable which looks like "MM/DD/YYYY"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that if everything in the original date variable was "YYYYMMDD" then I could do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new_date = input(put(date,8.),yymmdd8.);&lt;BR /&gt;format new_date mmddyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But since some "date" values are only 6 characters long it's throwing up error signs. I figure that if the date is missing I'll set the day to the first of the month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I set dates which only have a length of 6 to have a day value of "01" added to the end? I should be able to convert the new "YYYYMMDD" variable to "MM/DD/YYYY" myself afterwards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Fri, 29 May 2020 20:39:08 GMT</pubDate>
    <dc:creator>kkwan</dc:creator>
    <dc:date>2020-05-29T20:39:08Z</dc:date>
    <item>
      <title>Best way to handle multple date formats in one variable [data cleaning]</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Best-way-to-handle-multple-date-formats-in-one-variable-data/m-p/651876#M24149</link>
      <description>&lt;P&gt;I have a variable "date"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In most instances the date is reported as "YYYYMMDD" but in some instances the day is missing, so I only have "YYYYMM"&lt;/P&gt;&lt;P&gt;I ultimately want a date variable which looks like "MM/DD/YYYY"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that if everything in the original date variable was "YYYYMMDD" then I could do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new_date = input(put(date,8.),yymmdd8.);&lt;BR /&gt;format new_date mmddyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But since some "date" values are only 6 characters long it's throwing up error signs. I figure that if the date is missing I'll set the day to the first of the month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I set dates which only have a length of 6 to have a day value of "01" added to the end? I should be able to convert the new "YYYYMMDD" variable to "MM/DD/YYYY" myself afterwards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 20:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Best-way-to-handle-multple-date-formats-in-one-variable-data/m-p/651876#M24149</guid>
      <dc:creator>kkwan</dc:creator>
      <dc:date>2020-05-29T20:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to handle multple date formats in one variable [data cleaning]</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Best-way-to-handle-multple-date-formats-in-one-variable-data/m-p/651884#M24150</link>
      <description>&lt;P&gt;One way to trick this is to define a character variable that does not hold any more than 10 spaces to fully accommodate YYYY-MM-DD. Then you can append "-01-01". Only partial dates will be able to add the extra values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have ;
  length havedateC $15 ;
  havedateC = "2020-05-29" ;
  output ;
  havedateC = "2020-05" ;
  output ;
  havedateC = "2020" ;
  output ;
run ;

data want ;
   set have ;
   length fulldateC $10 ;
   fulldateC = strip(havedateC)||"-01-01" ;
   fulldateN = input(fulldateC,yymmdd10.) ;
   format fulldateN yymmdd10. ;
run ;

proc print ;
run ;&lt;/PRE&gt;
&lt;DIV id="div_18193ec6-a61a-4d59-8d62-4e6a5a604a12" class="c body" style="background-color: #fafbfe; color: #000000; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 1.231; orphans: 2; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; margin: 1em 8px 1em 8px;"&gt;
&lt;SECTION style="display: block; padding-bottom: 8px; padding-top: 1px;" data-name="Print" data-sec-type="proc"&gt;
&lt;ARTICLE id="IDX" style="display: block; padding-bottom: 8px; padding-top: 1px;" aria-label="Data Set WORK.WANT"&gt;
&lt;TABLE class="table" style="border-collapse: collapse; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-spacing: 0px; margin-bottom: 1em; margin-left: auto; margin-right: auto; border-width: 1px 0px 0px 1px; border-color: #c1c1c1; border-style: solid;" aria-label="Data Set WORK.WANT"&gt;&lt;CAPTION aria-label="Data Set WORK.WANT"&gt;&amp;nbsp;&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL style="border-left-color: #c1c1c1; border-left-style: solid; border-left-width: 1px; border-right-color: #c1c1c1; border-right-style: solid; border-right-width: 0px;" /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL style="border-left-color: #c1c1c1; border-left-style: solid; border-left-width: 1px; border-right-color: #c1c1c1; border-right-style: solid; border-right-width: 0px;" /&gt;&lt;COL style="border-left-color: #c1c1c1; border-left-style: solid; border-left-width: 1px; border-right-color: #c1c1c1; border-right-style: solid; border-right-width: 0px;" /&gt;&lt;COL style="border-left-color: #c1c1c1; border-left-style: solid; border-left-width: 1px; border-right-color: #c1c1c1; border-right-style: solid; border-right-width: 0px;" /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR style="border-bottom-color: #c1c1c1; border-bottom-style: solid; border-bottom-width: 0px; border-top-color: #c1c1c1; border-top-style: solid; border-top-width: 1px;"&gt;
&lt;TH class="r header" style="background-color: #edf2f9; color: #112277; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: bold; text-align: right; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #b0b7bb; border-style: solid; padding: 3px 6px 3px 6px;" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" style="background-color: #edf2f9; color: #112277; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: bold; text-align: left; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #b0b7bb; border-style: solid; padding: 3px 6px 3px 6px;" scope="col"&gt;havedateC&lt;/TH&gt;
&lt;TH class="header" style="background-color: #edf2f9; color: #112277; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: bold; text-align: left; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #b0b7bb; border-style: solid; padding: 3px 6px 3px 6px;" scope="col"&gt;fulldateC&lt;/TH&gt;
&lt;TH class="r header" style="background-color: #edf2f9; color: #112277; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: bold; text-align: right; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #b0b7bb; border-style: solid; padding: 3px 6px 3px 6px;" scope="col"&gt;fulldateN&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR style="border-bottom-color: #c1c1c1; border-bottom-style: solid; border-bottom-width: 0px; border-top-color: #c1c1c1; border-top-style: solid; border-top-width: 1px;"&gt;
&lt;TH class="r rowheader" style="background-color: #edf2f9; color: #112277; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: bold; text-align: right; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #b0b7bb; border-style: solid; padding: 3px 6px 3px 6px;" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: left; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020-05-29&lt;/TD&gt;
&lt;TD class="data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: left; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020-05-29&lt;/TD&gt;
&lt;TD class="r data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: right; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020-05-29&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="border-bottom-color: #c1c1c1; border-bottom-style: solid; border-bottom-width: 0px; border-top-color: #c1c1c1; border-top-style: solid; border-top-width: 1px;"&gt;
&lt;TH class="r rowheader" style="background-color: #edf2f9; color: #112277; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: bold; text-align: right; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #b0b7bb; border-style: solid; padding: 3px 6px 3px 6px;" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: left; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020-05&lt;/TD&gt;
&lt;TD class="data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: left; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020-05-01&lt;/TD&gt;
&lt;TD class="r data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: right; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020-05-01&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="border-bottom-color: #c1c1c1; border-bottom-style: solid; border-bottom-width: 0px; border-top-color: #c1c1c1; border-top-style: solid; border-top-width: 1px;"&gt;
&lt;TH class="r rowheader" style="background-color: #edf2f9; color: #112277; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: bold; text-align: right; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #b0b7bb; border-style: solid; padding: 3px 6px 3px 6px;" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: left; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020&lt;/TD&gt;
&lt;TD class="data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: left; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020-01-01&lt;/TD&gt;
&lt;TD class="r data" style="background-color: #ffffff; font-family: Arial,&amp;amp;quot; albany amt&amp;amp;quot;,helvetica,helv; font-size: x-small; font-style: normal; font-weight: normal; text-align: right; vertical-align: top; border-width: 0px 1px 1px 0px; border-color: #c1c1c1; border-style: solid; padding: 3px 6px 3px 6px;"&gt;2020-01-01&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/ARTICLE&gt;
&lt;/SECTION&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 21:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Best-way-to-handle-multple-date-formats-in-one-variable-data/m-p/651884#M24150</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-29T21:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to handle multple date formats in one variable [data cleaning]</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Best-way-to-handle-multple-date-formats-in-one-variable-data/m-p/651885#M24151</link>
      <description>&lt;P&gt;Depending on your current variable type:&lt;/P&gt;
&lt;PRE&gt;data junk;
  /* if your date was character*/
  input date $;
  if length(date)=8 then datevar=input(date,yymmdd10.);
  else if length(date)=6 then datevar=input(date,yymmn6.);
  format datevar mmddyy10.;

datalines;
20200305
202004
;

data junk2;
  /* if your date was numeric*/
  input date ;
  if length(put(date,best8. -L))=8 then datevar=input(put(date,best8. -L),yymmdd10.);
  else if length(put(date,best8. -L))=6 then datevar=input(put(date,best8. -L),yymmn6.);
  format datevar mmddyy10.;

datalines;
20200305
202004
;&lt;/PRE&gt;
&lt;P&gt;The YYMMN informat assumes the value is only year and month and treats it as the first day of the month.&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 21:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Best-way-to-handle-multple-date-formats-in-one-variable-data/m-p/651885#M24151</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-29T21:09:14Z</dc:date>
    </item>
  </channel>
</rss>

