<?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 convert date from $9. to ddmmyy8. ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841601#M332776</link>
    <description>&lt;P&gt;In other words - how to create a date from the variable NEW ?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data log_analysis ;&lt;BR /&gt;length Date_D 8 Date_M_ $3 Date_Y 4 ;&lt;BR /&gt;infile "/logs/ABC.log" end = EOF truncover ;&lt;BR /&gt;input ;&lt;BR /&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_M = scan(_infile_,7) ;&lt;BR /&gt;DATE_M_ = substr(DATE_M,1,3) ;&lt;BR /&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_D = scan(_infile_,8) ;&lt;BR /&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_Y = scan(_infile_,9) ;&lt;BR /&gt;NEW = compress(Date_D||Date_M_||Date_Y) ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
    <pubDate>Mon, 31 Oct 2022 11:16:21 GMT</pubDate>
    <dc:creator>J111</dc:creator>
    <dc:date>2022-10-31T11:16:21Z</dc:date>
    <item>
      <title>How to convert date from $9. to ddmmyy8. ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841597#M332772</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;What is the best way to convert Have data to Want data ?&lt;/P&gt;
&lt;P&gt;From 30OCT2021 to 301021 without informat as 30OCT2021 is actually created during a data step&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;-----------------------------------------------------------------&lt;BR /&gt;Data Have ;&lt;BR /&gt;input x9 $9. ;&lt;BR /&gt;cards ;&lt;BR /&gt;30OCT2021&lt;BR /&gt;3NOV2022&lt;BR /&gt;;&lt;BR /&gt;Run ;&lt;/P&gt;
&lt;P&gt;------------------------------------&lt;/P&gt;
&lt;P&gt;Data Want ;&lt;BR /&gt;input x10 ddmmyy8. ;&lt;BR /&gt;format x10 ddmmyy8. ;&lt;BR /&gt;cards ;&lt;BR /&gt;30102021&lt;BR /&gt;03112022&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 10:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841597#M332772</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-10-31T10:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date from $9. to ddmmyy8. ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841598#M332773</link>
      <description>&lt;P&gt;I'm not sure what you mean by 'without informat'?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, here is probably the easiest way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have ;
input x9 $9. ;
cards ;
30OCT2021
3NOV2022
;
Run ;


data want;
   set have;
   x10 = input(x9, date9.);
   format x10 ddmmyyn8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Oct 2022 10:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841598#M332773</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-31T10:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date from $9. to ddmmyy8. ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841601#M332776</link>
      <description>&lt;P&gt;In other words - how to create a date from the variable NEW ?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data log_analysis ;&lt;BR /&gt;length Date_D 8 Date_M_ $3 Date_Y 4 ;&lt;BR /&gt;infile "/logs/ABC.log" end = EOF truncover ;&lt;BR /&gt;input ;&lt;BR /&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_M = scan(_infile_,7) ;&lt;BR /&gt;DATE_M_ = substr(DATE_M,1,3) ;&lt;BR /&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_D = scan(_infile_,8) ;&lt;BR /&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_Y = scan(_infile_,9) ;&lt;BR /&gt;NEW = compress(Date_D||Date_M_||Date_Y) ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 11:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841601#M332776</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-10-31T11:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date from $9. to ddmmyy8. ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841603#M332778</link>
      <description>&lt;P&gt;Hoping for a shortcut to this:&lt;/P&gt;
&lt;P&gt;-----------------------------&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data log_analysis ;&lt;BR /&gt;length Date_D 8 Date_M_ $3 Date_Y 4 ;&lt;BR /&gt;infile "/opt/sas/prod_logs/BOI_SITE_INTRNL_STD_2022.10.31_07.06.21.log" end = EOF truncover ;&lt;BR /&gt;input ;&lt;BR /&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_M = scan(_infile_,7) ;&lt;BR /&gt;DATE_M_ = substr(DATE_M,1,3) ;&lt;/P&gt;
&lt;P&gt;if DATE_M_ = 'Jan' then month = 1 ;&lt;BR /&gt;else if DATE_M_ = 'Feb' then month = 2 ;&lt;BR /&gt;else if DATE_M_ = 'Mar' then month = 3 ;&lt;BR /&gt;else if DATE_M_ = 'Apr' then month = 4 ;&lt;BR /&gt;else if DATE_M_ = 'May' then month = 5 ;&lt;BR /&gt;else if DATE_M_ = 'Jun' then month = 6 ;&lt;BR /&gt;else if DATE_M_ = 'Jul' then month = 7 ;&lt;BR /&gt;else if DATE_M_ = 'Aug' then month = 8 ;&lt;BR /&gt;else if DATE_M_ = 'Sep' then month = 9 ;&lt;BR /&gt;else if DATE_M_ = 'Oct' then month = 10 ;&lt;BR /&gt;else if DATE_M_ = 'Nov' then month = 11 ;&lt;BR /&gt;else if DATE_M_ = 'Dec' then month = 12 ;&lt;/P&gt;
&lt;P&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_D = scan(_infile_,8) ;&lt;BR /&gt;if index(_infile_, 'The SAS System') &amp;gt; 0 then Date_Y = scan(_infile_,9) ;&lt;BR /&gt;Date_ = MDY(Month,Date_D,Date_Y) ;&lt;BR /&gt;format date_ ddmmyy8. ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 11:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841603#M332778</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-10-31T11:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date from $9. to ddmmyy8. ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841605#M332780</link>
      <description>&lt;P&gt;Why do you want to complicate things like this?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 11:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841605#M332780</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-31T11:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date from $9. to ddmmyy8. ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841608#M332782</link>
      <description>&lt;P&gt;agreeing with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;, you seem to be taking an unnecessarily complicated path. Why do you need months as numbers? Is it to make sure they sort in the proper order, rather than alphabetical order? Or some other reason, please specify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATE_M_ = substr(DATE_M,1,3) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We don't know what the value of DATE_M is, you haven't told us. However, since the first 3 characters of DATE_M could be 'JAN', then how about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date_m_= input(cats('01',substr(date_m,1,3),'2022'),date9.);
format date_m_ monname3.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you have a numeric SAS date value (example JAN) that appears to humans as JAN. So when you do the sorting of this numeric SAS date value, JAN is the first month, FEB is the second month, and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ADVICE: if you ever wind up with character strings that represent dates, convert them to numeric at the first opportunity using the INPUT function and the proper informat. DO NOT — I repeat&amp;nbsp;&lt;STRONG&gt;DO NOT&lt;/STRONG&gt; — try to pull "date" character strings apart and combine them back together as character strings. Work with numeric dates, SAS has already done the hard work to create functions, formats and informats that do all the hard work of handling dates. In addition, numeric values for dates will sort in numeric order, with JAN sorting before APR, whereas if you leave variables as character, they will sort alphabetically. Better yet, do not create dates as character strings in the first place, create them as numeric SAS date values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 11:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841608#M332782</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-31T11:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date from $9. to ddmmyy8. ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841626#M332795</link>
      <description>&lt;P&gt;cats function is very help full - many thanks&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 12:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841626#M332795</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-10-31T12:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date from $9. to ddmmyy8. ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841630#M332797</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386728"&gt;@J111&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please unmark your own response as correct.&lt;/P&gt;
&lt;P&gt;If you found my response to be the correct answer, mark that response as correct.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 13:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-from-9-to-ddmmyy8/m-p/841630#M332797</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-31T13:05:05Z</dc:date>
    </item>
  </channel>
</rss>

