<?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 extract year and month from date in SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377531#M90666</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132979"&gt;@lixuan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, if I wnna get a new variable of yymm in date format, how can I do?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could copy the date into another variable and attach a different format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdate= olddate ;
format olddate yymmdd10. newdate yymmn6. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise you will need to convert to something other than a date, since an actual date value requires a day of the month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdate_ch = put(olddate,yymmn6.);
newdate_num = input(put(olddate,yymmn6.),6.);
* or ;
newdate_num = year(olddate)*100 + month(olddate);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jul 2017 19:08:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-07-19T19:08:07Z</dc:date>
    <item>
      <title>How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377513#M90651</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;I have a variable in the form of yymmdd, and I want to extract yymm from it without changing the date format. I konw year() and month(),but I don't know how to get year and month in one variable. I asked the question just now and got the answer of using put to resolve it, but after use the method, i found the format is character. Here is my code. thanks a lot.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format dt yymmdd10.;
input dt yymmdd10.;
datalines;
2016-05-21
2017-08-12
2014-03-02
;
run;

data want;
set have;
yy = put(dt,yymmn6.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 18:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377513#M90651</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-19T18:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377515#M90653</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apply the FORMAT don't convert it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format dt yymmn6.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 18:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377515#M90653</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-19T18:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377524#M90662</link>
      <description>&lt;P&gt;Thanks, if I wnna get a new variable of yymm in date format, how can I do?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 19:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377524#M90662</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-19T19:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377527#M90664</link>
      <description>&lt;P&gt;Just input the result of your put. e.g.:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  yy = input(put(dt,yymmn6.),8.);
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 19:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377527#M90664</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-19T19:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377531#M90666</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132979"&gt;@lixuan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, if I wnna get a new variable of yymm in date format, how can I do?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could copy the date into another variable and attach a different format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdate= olddate ;
format olddate yymmdd10. newdate yymmn6. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise you will need to convert to something other than a date, since an actual date value requires a day of the month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdate_ch = put(olddate,yymmn6.);
newdate_num = input(put(olddate,yymmn6.),6.);
* or ;
newdate_num = year(olddate)*100 + month(olddate);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 19:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377531#M90666</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-19T19:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377540#M90669</link>
      <description>&lt;P&gt;Ok, Thank you . Combining with both your solvements, I get the answer, &amp;nbsp;however I wonder if there is a simpler way ?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  yy = input(put(dt,yymmn6.),8.);
  format yy yymmn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jul 2017 19:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377540#M90669</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-19T19:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377543#M90671</link>
      <description>&lt;P&gt;OK, I get it. Thank you all very much.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 19:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377543#M90671</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-19T19:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377545#M90673</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132979"&gt;@lixuan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Ok, Thank you . Combining with both your solvements, I get the answer, &amp;nbsp;however I wonder if there is a simpler way ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  yy = input(put(dt,yymmn6.),8.);
  format yy yymmn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You cannot apply the YYMMN format to a number like 201,707. &amp;nbsp;SAS stores dates as the number of days since start of 1960 so something like 201,707 would be in the year&amp;nbsp;2512, not in the year 2017.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 19:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377545#M90673</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-19T19:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377546#M90674</link>
      <description>&lt;P&gt;Yes, I check again and find that i am wrong. Thank you .&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 19:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377546#M90674</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-19T19:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract year and month from date in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377598#M90688</link>
      <description>&lt;P&gt;Another option is to duplicate the variable and then apply the format to the new variable. You can also apply formats in specific locations to override whats in your data. For example, if you want to create a report thats at the monthly level but only have data, you can apply the format in PROC REPORT or MEANS/TABULATE and it will aggregate correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 21:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-year-and-month-from-date-in-SAS/m-p/377598#M90688</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-19T21:11:51Z</dc:date>
    </item>
  </channel>
</rss>

