<?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: extract month and a year from date time field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365838#M86942</link>
    <description>&lt;P&gt;here is what I did&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let date1 = '01Jan2017'd;&lt;BR /&gt; &lt;BR /&gt;data temp_data;&lt;BR /&gt;set DB.TABLE(where = (&lt;BR /&gt;datepart(date_comp) &amp;gt; &amp;amp;date1) &lt;BR /&gt;);&lt;BR /&gt;format MONTH_YEAR yymon7.;&lt;BR /&gt;MONTH_YEAR = put(&lt;SPAN&gt;date_comp&lt;/SPAN&gt;, yymon7.);&lt;/P&gt;
&lt;P&gt;run;&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;
&lt;P&gt;the column MONTH_YEAR shows nothing, it's blank&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2017 21:06:16 GMT</pubDate>
    <dc:creator>tparvaiz</dc:creator>
    <dc:date>2017-06-09T21:06:16Z</dc:date>
    <item>
      <title>extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365788#M86921</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;need to extract month and a year from datetime field and here is what I have so far (which is not working)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let date1 = '01Jan2017'd;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp_data;&lt;BR /&gt; set DB.TABLE(where = (&lt;BR /&gt; datepart(date_comp) &amp;gt; &amp;amp;date1) &lt;BR /&gt; );&lt;/P&gt;
&lt;P&gt;format MONTH_YEAR &amp;nbsp;monyy7.;&lt;BR /&gt;MONTH_YEAR&amp;nbsp;= datepart(&lt;SPAN&gt;date_comp&lt;/SPAN&gt;);&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when I open the dataset, it shows month/year (e.g. JAN2017) but when I download it in excel&amp;nbsp;then it changes it to the date again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please advise&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 18:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365788#M86921</guid>
      <dc:creator>tparvaiz</dc:creator>
      <dc:date>2017-06-09T18:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365789#M86922</link>
      <description>&lt;P&gt;because of format monyy7. it displays so. Change it to something like yymmdd10. then it will display like date&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 19:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365789#M86922</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-09T19:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365790#M86923</link>
      <description>&lt;P&gt;The issue will lie somewhere in how you send the data to Excel. If you do not use something that allows use of attributes to set the EXCEL format, not SAS, then you get the default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tend to guess you are using Proc Export which generally has no controls over how data is sent as the appearance is not the purview of Export. Proc Export is for data values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are not using export then show code on how you are sending the data to Excel to see if we can make suggestions.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 19:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365790#M86923</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-09T19:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365791#M86924</link>
      <description>&lt;P&gt;I want month and a year and not the date...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 19:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365791#M86924</guid>
      <dc:creator>tparvaiz</dc:creator>
      <dc:date>2017-06-09T19:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365793#M86925</link>
      <description>&lt;P&gt;I am using proc export to save the file in xls format... something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC EXPORT DATA= Temp_data&lt;BR /&gt; OUTFILE= "C:\TEMP\DATA.xlsx" &lt;BR /&gt; DBMS=EXCEL REPLACE;&lt;BR /&gt; SHEET="DATA"; &lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 19:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365793#M86925</guid>
      <dc:creator>tparvaiz</dc:creator>
      <dc:date>2017-06-09T19:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365796#M86927</link>
      <description>&lt;P&gt;Sorry &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22922"&gt;@tparvaiz&lt;/a&gt;, it seems I have understood your question wrongly&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 19:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365796#M86927</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-09T19:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365804#M86932</link>
      <description>&lt;P&gt;Can you export the data and use XLSX engine? Or a more recent one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What you're seeing is SAS has a date, but the formats are not being passed to Excel. An alternative is to convert it to a character variable using PUT and then export.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date_month_year = put(date, yymon7.);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2017 19:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365804#M86932</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-09T19:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365838#M86942</link>
      <description>&lt;P&gt;here is what I did&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let date1 = '01Jan2017'd;&lt;BR /&gt; &lt;BR /&gt;data temp_data;&lt;BR /&gt;set DB.TABLE(where = (&lt;BR /&gt;datepart(date_comp) &amp;gt; &amp;amp;date1) &lt;BR /&gt;);&lt;BR /&gt;format MONTH_YEAR yymon7.;&lt;BR /&gt;MONTH_YEAR = put(&lt;SPAN&gt;date_comp&lt;/SPAN&gt;, yymon7.);&lt;/P&gt;
&lt;P&gt;run;&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;
&lt;P&gt;the column MONTH_YEAR shows nothing, it's blank&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 21:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365838#M86942</guid>
      <dc:creator>tparvaiz</dc:creator>
      <dc:date>2017-06-09T21:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365845#M86943</link>
      <description>&lt;P&gt;Format Month_year yymon7. ; will create a numeric variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PUT () creates a Character variable. So the result cannot be assigned to a numeric variable.&lt;/P&gt;
&lt;P&gt;You want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the format woud be $7.&lt;/P&gt;
&lt;P&gt;Format month_year $7. ;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 21:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365845#M86943</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-09T21:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365853#M86945</link>
      <description>&lt;P&gt;DATE_COMP is a datetime value, not a date value. &amp;nbsp;You can easily see that in your WHERE condition. &amp;nbsp;Just continue to treat it as a datetime value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MONTH_YEAR = datepart(date_comp);&lt;/P&gt;
&lt;P&gt;format month_year yymon7.;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 22:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365853#M86945</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-09T22:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365855#M86947</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MONTH_YEAR = put( DATEPART(date_comp), yymon7.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You're mixing things up, date and datetime, and character and numeric formats.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comment your code to avoid these types of errors.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 23:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365855#M86947</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-09T23:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: extract month and a year from date time field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365865#M86948</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22922"&gt;@tparvaiz&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I believe using ODS EXCEL is your most flexible option when it comes to a need to preserve formatting in the target Excel.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  picture dtyymon 
    other='%Y%b' (datatype=datetime)
  ;
run;
    
data Temp_data;
  format mySASDateTime dtyymon7. mySASDate yymon7.;
  mySASDateTime =datetime();
  mySASDate     =date();
  output;
run;

ods _all_ close;
ods excel
  file="c:\temp\test.xlsx"
  style=minimal
  ;
proc print noobs data=Temp_data;
run;
ods excel close;
ods listing;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Jun 2017 01:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-and-a-year-from-date-time-field/m-p/365865#M86948</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-10T01:22:56Z</dc:date>
    </item>
  </channel>
</rss>

