<?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: struggle with different date format in a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974112#M377800</link>
    <description>&lt;P&gt;Your are sure that yymmdd10 is the correct informat to read&amp;nbsp; '2035-07-02'? It could be yyddmm10, too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Sep 2025 10:25:54 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2025-09-04T10:25:54Z</dc:date>
    <item>
      <title>struggle with different date format in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974105#M377798</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;PRE&gt;data have;
format date_char $100. ;
date_char = '14/09/2035' ;
output;
date_char = '2035-07-02' ;
output ;
 
run;



data have2 ;
set have ;
format date_num1 date_num2 date9. ;
date_num1=input(date_char,ddmmyy10.);
date_num2=input(date_char,yymmdd10.); 
run ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hello&lt;/P&gt;
&lt;P&gt;I have a string column&amp;nbsp; that contains different format of dates.&lt;/P&gt;
&lt;P&gt;my aim is to get a column that transforms char in a date column.&lt;/P&gt;
&lt;P&gt;by using input, I get a missing value depending the input format.&lt;/P&gt;
&lt;P&gt;How could I get a colum that always works (without missing) whatever the format date of my source column date_char&lt;/P&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;
&lt;P&gt;Nasser&lt;/P&gt;</description>
      <pubDate>Thu, 04 Sep 2025 09:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974105#M377798</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2025-09-04T09:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: struggle with different date format in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974111#M377799</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n04jh1fkv5c8zan14fhqcby7jsu4.htm" target="_blank" rel="noopener"&gt;ANYDTDTE&lt;EM&gt;w&lt;/EM&gt;. informat&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date_num=input(date_char,anydtdte60.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But read the documentation to make sure that the results in cases of ambiguous or incomplete date strings (e.g., &lt;FONT face="courier new,courier"&gt;'03-02-01'&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;'APR15'&lt;/FONT&gt;) meet your requirements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, try to identify the reason for the inconsistent DATE_CHAR values (e.g., different data sources, countries, etc.) and then use more specific informats conditional on source, country, etc.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Sep 2025 10:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974111#M377799</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-09-04T10:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: struggle with different date format in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974112#M377800</link>
      <description>&lt;P&gt;Your are sure that yymmdd10 is the correct informat to read&amp;nbsp; '2035-07-02'? It could be yyddmm10, too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Sep 2025 10:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974112#M377800</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2025-09-04T10:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: struggle with different date format in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974114#M377801</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp;, I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;'s suggestion, using &lt;EM&gt;anydtdte.&lt;/EM&gt; to convert a character date column that has different date formats/informats for its values. The code and output is as follows (,and you do not need to create two columns for the numeric date value, creating one column is ok):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   format date_char $10.;
   date_char = '14/09/2035' ;output;
   date_char = '2035-07-02' ;output ;
run;
proc print data=have;run;
data have2 ;
   set have ;
   format date_num date9. ;
   date_num=input(date_char,anydtdte10.); 
run;
proc print data=have2;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1756982181125.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109611i734007963040A7B2/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1756982181125.png" alt="dxiao2017_0-1756982181125.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The reason you got missing values in your output is that, for your &lt;EM&gt;date_num1&lt;/EM&gt; column, you asks SAS to read a character date value using &lt;EM&gt;ddmmyy.&lt;/EM&gt; informat, however, &lt;EM&gt;2035-07-02&lt;/EM&gt; is not that informat, so its correspondence value in &lt;EM&gt;date_num1&lt;/EM&gt; is missing, similariy, for your &lt;EM&gt;date_num2&lt;/EM&gt; column, you asks SAS to read a character date value using &lt;EM&gt;yymmdd.&lt;/EM&gt; informat, however, &lt;EM&gt;14/09/2035&lt;/EM&gt; is not that informat, so its correspondence value in &lt;EM&gt;date_num2&lt;/EM&gt; is missing. And therefore, the solution is using &lt;EM&gt;anydtdte.&lt;/EM&gt; informat to let SAS read those values in your character date column with different informats, and creating only one numeric date column is sufficient enough to do this convertion.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Sep 2025 10:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/struggle-with-different-date-format-in-a-string/m-p/974114#M377801</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-09-04T10:45:47Z</dc:date>
    </item>
  </channel>
</rss>

