<?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: Converting a string column with multiple date formats to a  date column with a common date forma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-string-column-with-multiple-date-formats-to-a-date/m-p/981373#M379095</link>
    <description>&lt;P&gt;You might also explain where the data set J actually comes from.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are hints that this involves Excel as a possible data source. Which may mean that manipulation of the data set in Excel prior to reading into a SAS data set might be a better solution such as setting a single date format in the Excel column. Or save to a CSV text file and use a data step to read the data.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Dec 2025 15:52:10 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2025-12-30T15:52:10Z</dc:date>
    <item>
      <title>Converting a string column with multiple date formats to a  date column with a common date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-string-column-with-multiple-date-formats-to-a-date/m-p/981308#M379069</link>
      <description>&lt;P&gt;If you have a string column with multiple date formats in it, the following code can be used to convert all the strings into a proper date format and store in a separate date column. The code is written in SAS Studio in SAS Viya 4.0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Columns with multiple date format before running the code:&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="date01.png" style="width: 481px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112440iA00DD1C7225CB802/image-size/large?v=v2&amp;amp;px=999" role="button" title="date01.png" alt="date01.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Following code will read both the columns and apply the conditions to parse and convert date and create new date column with correct date format:&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;data find ;
    set j;
run;

data want;
  set j;
  PA_DOE_01=input(PA_DOE,??32.);
  if not missing(PA_DOE_01) then PA_DOE_01=int(PA_DOE_01)+'30dec1899'd;
  if missing(PA_DOE_01) then PA_DOE_01=input(prxchange('s/MONDAY|TUESDAY|SUNDAY//i',-1,PA_DOE),anydtdte40.);
  if missing(PA_DOE_01) then PA_DOE_01=input(tranwrd(PA_DOE,'00:00 ',' '),anydtdte40.);
 PA_DOI_01=input(PA_DOI,??32.);
  if not missing(PA_DOI_01) then PA_DOI_01=int(PA_DOI_01)+'30dec1899'd;
  if missing(PA_DOI_01) then PA_DOI_01=input(prxchange('s/MONDAY|TUESDAY|SUNDAY//i',-1,PA_DOI),anydtdte40.);
  if missing(PA_DOI_01) then PA_DOI_01=input(tranwrd(PA_DOI,'00:00 ',' '),anydtdte40.);
  format PA_DOE_01 PA_DOI_01 date9.;
run;&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;After running the above code, the two output columns PA_DOI_01 and PA_DOE_01 are the date columns with correct date format.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="date02.png" style="width: 718px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112441iAE81DFE98ADCA5D0/image-size/large?v=v2&amp;amp;px=999" role="button" title="date02.png" alt="date02.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Dec 2025 11:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-string-column-with-multiple-date-formats-to-a-date/m-p/981308#M379069</guid>
      <dc:creator>sachinrathod14</dc:creator>
      <dc:date>2025-12-26T11:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a string column with multiple date formats to a  date column with a common date forma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-string-column-with-multiple-date-formats-to-a-date/m-p/981310#M379070</link>
      <description>&lt;P&gt;You need to explain WHY that code works.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Dec 2025 14:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-string-column-with-multiple-date-formats-to-a-date/m-p/981310#M379070</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-26T14:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a string column with multiple date formats to a  date column with a common date forma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-string-column-with-multiple-date-formats-to-a-date/m-p/981373#M379095</link>
      <description>&lt;P&gt;You might also explain where the data set J actually comes from.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are hints that this involves Excel as a possible data source. Which may mean that manipulation of the data set in Excel prior to reading into a SAS data set might be a better solution such as setting a single date format in the Excel column. Or save to a CSV text file and use a data step to read the data.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Dec 2025 15:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-string-column-with-multiple-date-formats-to-a-date/m-p/981373#M379095</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-12-30T15:52:10Z</dc:date>
    </item>
  </channel>
</rss>

