<?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 Format Date Field in PROC SQL Question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224769#M40363</link>
    <description>&lt;P&gt;I am trying to format a date field to display in a YY_MM format in proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;09/09/2015&amp;nbsp; display as 15_09&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I attempted to use the datepart function: datepart(date_field, 'YY_MM') as date_test&amp;nbsp;however, received this error:&lt;/P&gt;
&lt;P&gt;No authorized routine named "DATEPART" of type "DATEPART" having&lt;/P&gt;
&lt;P&gt;compatible arguments was found. SQLSTATE=42884&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Sep 2015 15:42:27 GMT</pubDate>
    <dc:creator>PhatRam33</dc:creator>
    <dc:date>2015-09-09T15:42:27Z</dc:date>
    <item>
      <title>Format Date Field in PROC SQL Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224769#M40363</link>
      <description>&lt;P&gt;I am trying to format a date field to display in a YY_MM format in proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;09/09/2015&amp;nbsp; display as 15_09&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I attempted to use the datepart function: datepart(date_field, 'YY_MM') as date_test&amp;nbsp;however, received this error:&lt;/P&gt;
&lt;P&gt;No authorized routine named "DATEPART" of type "DATEPART" having&lt;/P&gt;
&lt;P&gt;compatible arguments was found. SQLSTATE=42884&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 15:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224769#M40363</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2015-09-09T15:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Format Date Field in PROC SQL Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224774#M40365</link>
      <description>&lt;P&gt;You can create another variable based on your date and format this accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't pretty and will probably be improved on by others but it does work!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have ;&lt;BR /&gt;format dte ddmmyy10. ;&lt;BR /&gt;dte = '03feb2015'd ; output ;&lt;BR /&gt;dte = '15apr2002'd ; output ;&lt;BR /&gt;dte = '28oct1999'd ; output ;&lt;BR /&gt;run ;&lt;BR /&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;create table want as&lt;BR /&gt;select dte,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; substr(compress(put(year(dte),8.)),3,2)||'_'||compress(put(month(dte),z2.)) as dte2 &lt;BR /&gt;from&amp;nbsp;&amp;nbsp; have ;&lt;BR /&gt;quit ;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 15:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224774#M40365</guid>
      <dc:creator>FatCaptain</dc:creator>
      <dc:date>2015-09-09T15:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Format Date Field in PROC SQL Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224778#M40366</link>
      <description>&lt;P&gt;Here you go:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile cards dsd;&lt;BR /&gt;input date;&lt;BR /&gt;informat date mmddyy10.;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;09/09/2015&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;date2 = date;&lt;BR /&gt;format date2 yymmn4.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 16:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224778#M40366</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-09T16:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Format Date Field in PROC SQL Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224786#M40369</link>
      <description>&lt;P&gt;There would many ways to do this, among which (assuming &lt;EM&gt;date_field&lt;/EM&gt; is a datetime value) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
date_field = '15SEP2005:12:00:00'dt;
format date_field datetime19.;
run;

proc sql;
select translate(put(datepart(date_field), yymm5.), "_", "M") as date_string
from test;
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 17:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224786#M40369</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-09-09T17:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Format Date Field in PROC SQL Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224791#M40371</link>
      <description>&lt;P&gt;If it has to be an underscore you have a solution above, but it will not be a date field.&amp;nbsp; If a slash helps this will work and it maintains being a date field for calculation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile cards;&lt;BR /&gt;informat date mmddyy10.;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;input date;&lt;BR /&gt;cards;&lt;BR /&gt;09/09/2015&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select date,date as date2 format=yymms5.&lt;BR /&gt;from have;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 17:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224791#M40371</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-09T17:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Format Date Field in PROC SQL Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224809#M40374</link>
      <description>&lt;P&gt;Thank you very much everyone for the help.&amp;nbsp; I will give this a shot and follow-up.&amp;nbsp; Basically from what I gather, it seems like a 2 step process to format the date field as YY_MM.&amp;nbsp; Yes, it will no longer be a date type field which is fine so the underscore should be ok.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 18:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/224809#M40374</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2015-09-09T18:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Format Date Field in PROC SQL Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/225270#M40418</link>
      <description>&lt;P&gt;You could make your own picture format to do that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  picture yy_mm
     low-high = '%0y_%0m' (datatype=datetime)
  ;
run;
data _null_;
  dt=datetime();
  put dt datetime20. / dt yy_mm5. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Sep 2015 13:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Date-Field-in-PROC-SQL-Question/m-p/225270#M40418</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-12T13:35:04Z</dc:date>
    </item>
  </channel>
</rss>

