<?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: Date format in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846330#M334590</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set want = datepart(have);
forma want yymmddn7.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no SET command that does this in a SAS data step. The command is simply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want=datepart(have);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you assign the proper format. You need 8 digits, so a format of 7 digits will not work. You also need to correct spelling and syntax errors in your FORMAT command.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Nov 2022 15:11:53 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-11-25T15:11:53Z</dc:date>
    <item>
      <title>Date format in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846329#M334589</link>
      <description>&lt;P&gt;Hi SAS community.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had posted a similar question here few years ago. I am facing the same issue and my old code does not address it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the problem:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS file that I would like to save into CSV. Before that, I need the date format be easily read and understood under CSV. Currently, the date variable I have looks like&lt;/P&gt;&lt;P&gt;01NOV01 :00:00:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The PROC CONTENTS command indicates the format to be DATETIME and the informat is ANYDTDTM40.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to convert this to 20011101. And I have been trying variations of this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set want = datepart(have);&lt;/P&gt;&lt;P&gt;forma want yymmddn7.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where I replaced yymmddn7. with other formats. I either do not see any change to the variable or it just disappears.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried&lt;/P&gt;&lt;P&gt;mydates = input(put(mydates, 8.), yymmdd8.);&lt;/P&gt;&lt;P&gt;format date&lt;/P&gt;&lt;P&gt;format mydates monyy7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;still no results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any piece of advice if appreciated. Notice that I'm not a SAS nerd, I only use it everytime I need to load some big amount of financial data.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 15:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846329#M334589</guid>
      <dc:creator>ali11</dc:creator>
      <dc:date>2022-11-25T15:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Date format in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846330#M334590</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set want = datepart(have);
forma want yymmddn7.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no SET command that does this in a SAS data step. The command is simply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want=datepart(have);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you assign the proper format. You need 8 digits, so a format of 7 digits will not work. You also need to correct spelling and syntax errors in your FORMAT command.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 15:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846330#M334590</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-25T15:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Date format in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846331#M334591</link>
      <description>&lt;P&gt;Length of 7 doesn't really makes sense, since you want 8?&lt;/P&gt;
&lt;P&gt;Have you tried yymmddn8.?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 15:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846331#M334591</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-11-25T15:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Date format in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846333#M334593</link>
      <description>&lt;P&gt;thanks! it is now working well &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 15:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846333#M334593</guid>
      <dc:creator>ali11</dc:creator>
      <dc:date>2022-11-25T15:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Date format in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846366#M334601</link>
      <description>&lt;P&gt;So a few points.&lt;/P&gt;
&lt;P&gt;The variable you have does not have date values. It has datetime values.&amp;nbsp; SAS stores dates as number of days and datetime as number of seconds.&amp;nbsp; So to convert the value from a datetime value to a date value you need to divide by the number of seconds in a day.&amp;nbsp; SAS provides a handy function, DATEPART(), that will do that for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the value in the CSV file to be something that anyone looking at the CSV file will understand is a date then do not use a value like&amp;nbsp;&lt;SPAN&gt;20011101.&amp;nbsp; That just looks like a number. Since there is no place in a CSV to store any metadata to indicate it isn't that number then most people (and programs) looking at the CSV file will assume it is just the number&amp;nbsp;20,011,101 instead of a date.&amp;nbsp; It would be better to use something like 2001-11-01 instead.&amp;nbsp; The hyphens will let the reader know it isn't a number.&amp;nbsp; And displaying the date in YMD order will avoid the ambiguity caused by using either MDY or DMY order.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_export;
  set have;
  mydates=datepart(mydates);
  format mydates yymmdd10.;
run;
proc export data=for_export file="want.csv" dbms=csv replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if actually have some consumer of the CSV file that &lt;STRONG&gt;requires&lt;/STRONG&gt; that the dates be written in the file in that confusing YYYYMMDD style then you could leave the values as DATETIME values and just apply the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p0c419d4254oddn19koluiafrsel.htm" target="_self"&gt;E8601DN&lt;/A&gt; format to the variable.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 19:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format-in-SAS/m-p/846366#M334601</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-25T19:09:32Z</dc:date>
    </item>
  </channel>
</rss>

