<?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: create a yearmonth variable with YYMMn6. format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/390490#M93681</link>
    <description>&lt;P&gt;Sas date counts days since 01/01/1960 = 0;&lt;/P&gt;
&lt;P&gt;If you convert the two input variables to date it is just simple numeric comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, as your char-date is in yyyymm format, you can compare them as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;alphanumeric strings. If it was in mmyyyy format it will give false results.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Aug 2017 04:14:04 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-08-24T04:14:04Z</dc:date>
    <item>
      <title>create a yearmonth variable with YYMMn6. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/389451#M93377</link>
      <description>&lt;P&gt;I would like to create a new variable that take YYMMn6 format to display yearmonth, taking value from another numeric variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, the original numeric variable has value 199312, the new variable would display the same value "199312".&lt;/P&gt;&lt;P&gt;So far I have tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format new_yearmonth = put(yearmonth, YYMMn6.);
* but this take yearmonth value as date value and convert this to a weird number 245603 or something;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have successfully converted something similar to yearquarter format with the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format yearquarter YYQn6.;
yearquarter = YYQ(year,quarter);
*where year is a numeric variable having value 1993, quarter is also a numeric variable that has value 1, 2, 3, and 4;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I guess I can also try this method but could not find a function similar to YYQ that takes value of 2 variable year and month. Is there such function?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 05:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/389451#M93377</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2017-08-21T05:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: create a yearmonth variable with YYMMn6. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/389456#M93380</link>
      <description>This is really confusing. What do you have? What do you want?</description>
      <pubDate>Mon, 21 Aug 2017 05:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/389456#M93380</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-21T05:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: create a yearmonth variable with YYMMn6. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/389459#M93382</link>
      <description>I have a yearmonth variable whose format is numeric ( value could be 199311 or 201009)&lt;BR /&gt;I want a new variable whose format is YYMMn6 and displays values 199311 or 201009.&lt;BR /&gt;The purpose is that when I draw graph, there is no gap between 199312 and 199401&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Aug 2017 06:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/389459#M93382</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2017-08-21T06:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: create a yearmonth variable with YYMMn6. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/389464#M93383</link>
      <description>&lt;P&gt;You need first to convert the input numeric variable to a sas date variable.&lt;/P&gt;
&lt;P&gt;Sas date contains: year, month and day.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having input like &lt;STRONG&gt;var = 201706&lt;/STRONG&gt; - the day is absent. You can choose any day to adjust to the input.&lt;/P&gt;
&lt;P&gt;In such cases ususally we adjust day=01;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many ways to convert your input to a&lt;STRONG&gt; sas date.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In order to display the sas date as yyyymm assign to it the format &amp;nbsp;YYMMN6.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Format new_date yymmn6.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;1) using&amp;nbsp;&lt;STRONG&gt;MDY&lt;/STRONG&gt; function - needs to split your input to year and month:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_date = mdy(mod(var,100), 01, int(var/100) );
/* -------     month        day     year    -------*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) alternatively, convert the number given to a string and adjust the day:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_date = input(put(var,6.),yymmdd8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) The most simple way to convert the input to a sas date - which maybe you used is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_date = input(put(var,6.), yymmn6.);
format new_date yymmn6.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Aug 2017 07:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/389464#M93383</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-21T07:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: create a yearmonth variable with YYMMn6. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/390489#M93680</link>
      <description>&lt;P&gt;Thank you so much. it works perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a quick question. How do we compare the date? for example, if I want dates after 199702? Since it is not numeric, I cannot simply do &amp;gt;199702.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 04:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/390489#M93680</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2017-08-24T04:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: create a yearmonth variable with YYMMn6. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/390490#M93681</link>
      <description>&lt;P&gt;Sas date counts days since 01/01/1960 = 0;&lt;/P&gt;
&lt;P&gt;If you convert the two input variables to date it is just simple numeric comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, as your char-date is in yyyymm format, you can compare them as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;alphanumeric strings. If it was in mmyyyy format it will give false results.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 04:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/390490#M93681</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-24T04:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: create a yearmonth variable with YYMMn6. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/397329#M96021</link>
      <description>Hi Shmuel,&lt;BR /&gt;While we are on this topic, I would like to create a variable that represent year and has format YEAR4. . This take values from a different variable that already shows years but in numeric format (best8.). How would I do this?&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 20 Sep 2017 05:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/397329#M96021</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2017-09-20T05:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: create a yearmonth variable with YYMMn6. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/397338#M96024</link>
      <description>&lt;P&gt;YEAR4. format is applicable with a sas date varibale.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your variable as a numeric year only (used with BEST4. format) then&amp;nbsp;&lt;/P&gt;
&lt;P&gt;convert it with MDY function, adding any month or day and assign the YEAR4. format.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 06:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-yearmonth-variable-with-YYMMn6-format/m-p/397338#M96024</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-09-20T06:50:59Z</dc:date>
    </item>
  </channel>
</rss>

