<?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: URGENT: extract Year and Month from a date variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288784#M59602</link>
    <description>&lt;P&gt;The issue is that FIRST_CHEMO_DATE is already defined as a character variable. &amp;nbsp;You can't change it to numeric. &amp;nbsp;One approach to solving this would be to create a new variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;first_chemo_&lt;FONT color="#FF00FF"&gt;sas&lt;/FONT&gt;date=input(put(first_chemo_date,8.0,yy&lt;/SPAN&gt;&lt;WBR /&gt;&lt;SPAN&gt;mmdd8.); format first_chemo_&lt;FONT color="#FF00FF"&gt;sas&lt;/FONT&gt;date yymmddn8.;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then apply the YEAR and MONTH functions to the new variable. &amp;nbsp;Another alternative would be to read the existing character date. &amp;nbsp;For example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;yearvar = input(first_chemo_date, 4.);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;monthvar = input(substr(first_chemo_date, 5), 2.);&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Aug 2016 01:41:32 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-08-02T01:41:32Z</dc:date>
    <item>
      <title>URGENT: extract Year and Month from a date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288783#M59601</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need a very urgent help:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can I extract Year and Month from a date variable that is formatted as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dat w.cancer; set c.cancer;&lt;/P&gt;&lt;P&gt;first_chemo_date=input(put(first_chemo_date,8.0,yymmdd8.); format first_chemo_date yymmddn8.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so the date variable looks like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first_chemo_date&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;20150208&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;20140722&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;20110618&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;year(first_chemo_date) &amp;amp; month(first_chemo_date)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and substr command, but they do not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help please? this is a very urgent matter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 01:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288783#M59601</guid>
      <dc:creator>sasworker16</dc:creator>
      <dc:date>2016-08-02T01:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: URGENT: extract Year and Month from a date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288784#M59602</link>
      <description>&lt;P&gt;The issue is that FIRST_CHEMO_DATE is already defined as a character variable. &amp;nbsp;You can't change it to numeric. &amp;nbsp;One approach to solving this would be to create a new variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;first_chemo_&lt;FONT color="#FF00FF"&gt;sas&lt;/FONT&gt;date=input(put(first_chemo_date,8.0,yy&lt;/SPAN&gt;&lt;WBR /&gt;&lt;SPAN&gt;mmdd8.); format first_chemo_&lt;FONT color="#FF00FF"&gt;sas&lt;/FONT&gt;date yymmddn8.;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then apply the YEAR and MONTH functions to the new variable. &amp;nbsp;Another alternative would be to read the existing character date. &amp;nbsp;For example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;yearvar = input(first_chemo_date, 4.);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;monthvar = input(substr(first_chemo_date, 5), 2.);&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 01:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288784#M59602</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-02T01:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: URGENT: extract Year and Month from a date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288803#M59609</link>
      <description>&lt;P&gt;What error messages and notes did you get when you ran that code?&lt;/P&gt;
&lt;P&gt;You are missing a closing ).&lt;/P&gt;
&lt;P&gt;If your source variable is NUMERIC then you could do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data  want ;
  set have ;
  first_chemo_date=input(put(first_chemo_date,Z8.),yymmdd8.);
  format first_chemo_date yymmddn8.;
  yr=year(first_chemo_date);
  mth=month(first_chemo_date);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your source variable is CHARACTER then you need to make a NEW variable if want to store it as an actual date value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  first_chemo_date_num=input(first_chemo_date,yymmdd8.);
  format first_chemo_date_num yymmddn8.;
  yr=year(first_chemo_date_num);
  mth=month(first_chemo_date_num);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 03:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288803#M59609</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-08-02T03:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: URGENT: extract Year and Month from a date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288819#M59617</link>
      <description>&lt;P&gt;Thank you very much for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 05:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/m-p/288819#M59617</guid>
      <dc:creator>sasworker16</dc:creator>
      <dc:date>2016-08-02T05:35:57Z</dc:date>
    </item>
  </channel>
</rss>

