<?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 Date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/402967#M278885</link>
    <description>&lt;P&gt;I am pretty new on SAS and I am not getting to create a new variable in SAS based on a date variable with the format&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;monname9.&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;I want to add the year season for each month in the&amp;nbsp;monname9. date, for example, I want to create a variable called&amp;nbsp;Year Season for December, January and February I want to put "winter"&lt;/P&gt;&lt;P class="p1"&gt;March, April and May I want to call "spring"&lt;/P&gt;&lt;P class="p1"&gt;June, July and August call "summer"&lt;/P&gt;&lt;P class="p1"&gt;and the other 3 months "fall"&lt;/P&gt;&lt;P class="p1"&gt;this should repeat for some years in my data.&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;Any thoughts how I could do that?&lt;/P&gt;&lt;P class="p1"&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 10 Oct 2017 22:08:31 GMT</pubDate>
    <dc:creator>Giovani</dc:creator>
    <dc:date>2017-10-10T22:08:31Z</dc:date>
    <item>
      <title>Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/402967#M278885</link>
      <description>&lt;P&gt;I am pretty new on SAS and I am not getting to create a new variable in SAS based on a date variable with the format&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;monname9.&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;I want to add the year season for each month in the&amp;nbsp;monname9. date, for example, I want to create a variable called&amp;nbsp;Year Season for December, January and February I want to put "winter"&lt;/P&gt;&lt;P class="p1"&gt;March, April and May I want to call "spring"&lt;/P&gt;&lt;P class="p1"&gt;June, July and August call "summer"&lt;/P&gt;&lt;P class="p1"&gt;and the other 3 months "fall"&lt;/P&gt;&lt;P class="p1"&gt;this should repeat for some years in my data.&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;Any thoughts how I could do that?&lt;/P&gt;&lt;P class="p1"&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 22:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/402967#M278885</guid>
      <dc:creator>Giovani</dc:creator>
      <dc:date>2017-10-10T22:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/402985#M278886</link>
      <description>&lt;P&gt;Is this supposed to have the YEAR value as part of the result or not?&lt;/P&gt;
&lt;P&gt;I.E Dec 2016 = "Winter" or Dec 2016= "Winter 2016"?&lt;/P&gt;
&lt;P&gt;And if year is part of the result would Dec 2016, Jan 2017 and Feb 2017 all be "Winter 2016", "Winter 2017" or the year per calendar month?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 23:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/402985#M278886</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-10T23:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/402994#M278887</link>
      <description>&lt;P&gt;Use a FORMAT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/170866"&gt;@Giovani&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am pretty new on SAS and I am not getting to create a new variable in SAS based on a date variable with the format&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;monname9.&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;I want to add the year season for each month in the&amp;nbsp;monname9. date, for example, I want to create a variable called&amp;nbsp;Year Season for December, January and February I want to put "winter"&lt;/P&gt;
&lt;P class="p1"&gt;March, April and May I want to call "spring"&lt;/P&gt;
&lt;P class="p1"&gt;June, July and August call "summer"&lt;/P&gt;
&lt;P class="p1"&gt;and the other 3 months "fall"&lt;/P&gt;
&lt;P class="p1"&gt;this should repeat for some years in my data.&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Any thoughts how I could do that?&lt;/P&gt;
&lt;P class="p1"&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 00:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/402994#M278887</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-11T00:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/403000#M278888</link>
      <description>&lt;P&gt;Here some code demonstrating how you could create a format "Season."&amp;nbsp;for use with your data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ctrl;
  fmtname='Seasons';
  format start end date9.;
  do i=0 by 1;
    start =intnx('month','01jan1960'd,i*3,'b');
    end   =intnx('month',start,2,'e');
    select(month(start));
      when(12,1,2)  label='Winter';
      when(3,4,5)   label='Spring';
      when(6,7,8)   label='Summer';
      when(9,10,11) label='Fall';
      otherwise;
    end;
    output;
    if start &amp;gt; intnx('year',today(),5,'e') then leave;
  end;
run;

proc format cntlin=ctrl;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Documented here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n1e19y6lrektafn1kj6nbvhus59w.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&amp;nbsp;" target="_blank"&gt;http://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n1e19y6lrektafn1kj6nbvhus59w.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&amp;nbsp;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 00:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/403000#M278888</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-11T00:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/403164#M278889</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the reply. Just the season "winter" is the expected result.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 13:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/403164#M278889</guid>
      <dc:creator>Giovani</dc:creator>
      <dc:date>2017-10-11T13:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/403167#M278890</link>
      <description>&lt;P&gt;Thanks for the reply!&lt;/P&gt;&lt;P&gt;I went true the codes and this created all the years season from 1960 until&amp;nbsp;today, but that is not what I was expecting.&lt;/P&gt;&lt;P&gt;I do have a variable Month with many observations starting in 2003&amp;nbsp;going&amp;nbsp;until nowadays. The variable month has a format MONNAME9.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to create a new variable matching each l&lt;SPAN&gt;ine in the variable Month&lt;/SPAN&gt;&amp;nbsp;with a&amp;nbsp;corresponding&amp;nbsp;line in the&amp;nbsp; new variable Season with a label of winter, fall, summer, or spring.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 13:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/403167#M278890</guid>
      <dc:creator>Giovani</dc:creator>
      <dc:date>2017-10-11T13:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/403194#M278891</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/170866"&gt;@Giovani&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking to create a new variable matching each l&lt;SPAN&gt;ine in the variable Month&lt;/SPAN&gt;&amp;nbsp;with a&amp;nbsp;corresponding&amp;nbsp;line in the&amp;nbsp; new variable Season with a label of winter, fall, summer, or spring.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you try applying the format created? See the full example below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Create a format;
data ctrl;
  fmtname='Seasons';
  format start end date9.;
  do i=0 by 1;
    start =intnx('month','01jan1960'd,i*3,'b');
    end   =intnx('month',start,2,'e');
    select(month(start));
      when(12,1,2)  label='Winter';
      when(3,4,5)   label='Spring';
      when(6,7,8)   label='Summer';
      when(9,10,11) label='Fall';
      otherwise;
    end;
    output;
    if start &amp;gt; intnx('year',today(),5,'e') then leave;
  end;
run;

proc format cntlin=ctrl;
run;

*demo application of format;
data want;
    format date date9. date_formatted seasons.;

    do date='01Jan2016'd to '31Dec2017'd;
        date_formatted = date;
        date_char =put(date, seasons.);
        output;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2017 14:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/403194#M278891</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-11T14:52:00Z</dc:date>
    </item>
  </channel>
</rss>

