<?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 display Dates in Character Format? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453504#M114596</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I managed to create one of the two variables using datepart function. However I'm seeking your help to create the variable and value as below (last day of previous month) and it should be in character format. &amp;nbsp;Challenge which i have here is to make this as a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SDDTOP = 2018-03-31&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The way I went about this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Google search:&amp;nbsp; &amp;nbsp;site:support.sas.com 9.4 formats and informats&lt;/P&gt;
&lt;P&gt;That returns as the very first hit:&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm&amp;nbsp;" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2. Go to the documentation for Formats&lt;/P&gt;
&lt;P&gt;3. Open up "Formats by category"&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 181px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19742i4E8C50018742E5A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;4. search for yyyy-&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;....and this then led me to format&amp;nbsp;&lt;STRONG&gt;e8601dn.&lt;/STRONG&gt; which returns exactly what you're asking for without even the need to first convert your SAS datetime to a date value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  have='31JAN2017:00:00:00'dt;
  format have datetime23.;
  want=put(have,e8601dn.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 260px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19743iEF2BA8F938AE03CC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Apr 2018 11:41:07 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2018-04-12T11:41:07Z</dc:date>
    <item>
      <title>How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453476#M114587</link>
      <description>&lt;P&gt;Appreciate if someone of you help me understand to create the variable 'SDDTOP' and it should have the date value (last day of previous month) &amp;nbsp;with character format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g.&amp;nbsp;&amp;nbsp;SDDTOP=2018-03-31&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 09:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453476#M114587</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-04-12T09:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453478#M114588</link>
      <description>&lt;P&gt;Use the intnx function and a yymmddd10. format.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 09:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453478#M114588</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-12T09:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453482#M114589</link>
      <description>&lt;P&gt;I already tried this, but it is in numeric format. I want it to be in character format.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 10:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453482#M114589</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-04-12T10:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453483#M114590</link>
      <description>&lt;P&gt;Post your code.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 10:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453483#M114590</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-12T10:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453484#M114591</link>
      <description>&lt;P&gt;I tried this code and end up with the invalid values like &lt;STRONG&gt;******** &lt;/STRONG&gt;for the variable b and c.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
a='31JAN2017:00:00:00'dt;
format a datetime23.;
b=PUT(a,date9.);
c=put(a,YYMMDD10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My objective is to create two&amp;nbsp;new variable based on the variable 'a'. One variable (e.g. 'b') should have value the&amp;nbsp;&lt;STRONG&gt;31JAN2017&lt;/STRONG&gt; in numeric&amp;nbsp;format and another one &lt;SPAN&gt;(e.g. 'c') &lt;/SPAN&gt;should have the value &lt;STRONG&gt;2017-01-31&lt;/STRONG&gt; and it should be in character format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 10:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453484#M114591</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-04-12T10:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453485#M114592</link>
      <description>&lt;P&gt;So you do not have a &lt;STRONG&gt;DATE&lt;/STRONG&gt; value, as you told lyingly to us, but a &lt;STRONG&gt;DATETIME&lt;/STRONG&gt; value. As you were told probably a hundred times now, a date value is a count of DAYS, while a datetime value is a count of SECONDS, so a datetime value is MUCH too big for a date format. There is a magic function called DATEPART that extracts the date out of a datetime. USE IT.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 10:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453485#M114592</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-12T10:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453496#M114593</link>
      <description>&lt;P&gt;I managed to create one of the two variables using datepart function. However I'm seeking your help to create the variable and value as below (last day of previous month) and it should be in character format. &amp;nbsp;Challenge which i have here is to make this as a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SDDTOP = 2018-03-31&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453496#M114593</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-04-12T11:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453497#M114594</link>
      <description>&lt;P&gt;put() function converts numeric to character.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453497#M114594</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-12T11:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453502#M114595</link>
      <description>&lt;PRE&gt;data test;
  a='31JAN2017:00:00:00'dt;
  format a datetime23.;
  b=put(datepart(a),date9.);
  c=put(datepart(a),yymmdd10.);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453502#M114595</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-04-12T11:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453504#M114596</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I managed to create one of the two variables using datepart function. However I'm seeking your help to create the variable and value as below (last day of previous month) and it should be in character format. &amp;nbsp;Challenge which i have here is to make this as a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SDDTOP = 2018-03-31&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The way I went about this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Google search:&amp;nbsp; &amp;nbsp;site:support.sas.com 9.4 formats and informats&lt;/P&gt;
&lt;P&gt;That returns as the very first hit:&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm&amp;nbsp;" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2. Go to the documentation for Formats&lt;/P&gt;
&lt;P&gt;3. Open up "Formats by category"&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 181px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19742i4E8C50018742E5A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;4. search for yyyy-&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;....and this then led me to format&amp;nbsp;&lt;STRONG&gt;e8601dn.&lt;/STRONG&gt; which returns exactly what you're asking for without even the need to first convert your SAS datetime to a date value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  have='31JAN2017:00:00:00'dt;
  format have datetime23.;
  want=put(have,e8601dn.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 260px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19743iEF2BA8F938AE03CC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453504#M114596</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-04-12T11:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453506#M114598</link>
      <description>What if the value of 'have' is 2017-03-31 in numeric format and I just to&lt;BR /&gt;need to convert it to character?  Can I use the put function with the&lt;BR /&gt;format $10.?&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453506#M114598</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-04-12T11:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453509#M114600</link>
      <description>&lt;P&gt;Well, 2017-03-31 gives an interesting numeric value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
x1 = 2017-03-31;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453509#M114600</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-12T11:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to display Dates in Character Format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453511#M114601</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt; wrote:&lt;BR /&gt;What if the value of 'have' is 2017-03-31 in numeric format and I just to&lt;BR /&gt;need to convert it to character? Can I use the put function with the&lt;BR /&gt;format $10.?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I would have thought you understand in-between how SAS Date and DateTime values work. If the value is numeric then it's either the count of days (date value) or seconds (datetime value) since 1/1/1960. You then apply a format to make this value human readable as a date/datetime value. This doesn't change the value itself which just remains a number, the format is just for printing.&lt;/P&gt;
&lt;P&gt;If you really want to store such a numeric value representing a data/datetime in a character variable, then you have to use the put() function. This function does nothing else than applying the format you use to your numeric value and then write the result as a string - and if this is on the right side from the equal sign then you're assigning this string value to a character variable. In other languages the comparable function to a SAS put() is called write()&amp;nbsp; - and read() for input().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Can I use the put function with the&amp;nbsp;format $10.?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I hope you understand now that the answer to this question is "no, of course not". You have to use the appropriate date/datetime format to write the number as a date/datetime string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And last but not least: It's really MUCH better to keep dates as SAS date/datetime values (=numeric) with a format permanently assigned to the variable for printing/looking at it. Keeping the dates numeric allows you to actually use such data (i.e. if you want to calculated the number of days between two dates and the like; or even if you just want to sort by date).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 13:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-Dates-in-Character-Format/m-p/453511#M114601</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-04-12T13:09:09Z</dc:date>
    </item>
  </channel>
</rss>

