<?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: &amp;quot;PUT&amp;quot; function returning wrong year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869676#M343522</link>
    <description>&lt;P&gt;Thanks for this explanation, Reeza. I reran the original code and you're right: it wasn't working. I don't know why I thought it was.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, I tender my gratitude for your taking the time to respond.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 22:20:44 GMT</pubDate>
    <dc:creator>dbcrow</dc:creator>
    <dc:date>2023-04-13T22:20:44Z</dc:date>
    <item>
      <title>"PUT" function returning wrong year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869669#M343517</link>
      <description>&lt;P&gt;Hi, SAS Users-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Me again. I'm trying to change a date (stored in two variables, one with a SAS date format and the other as numeric) to a string variable with a two-digit year and a three character month abbreviation--e.g., "16-Jan".&amp;nbsp; Ultimately, I want to join the data I'm prepping with another file, which has months in this format. But instead of getting "16-Jan", I get "65-Jan":&amp;nbsp; right month, but wrong year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code I'm using:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;data ucd5;
	set ucd4;

	highmme_rate = highmme/pop*100000;
	month = put(date2, monname3.);
	monyear2 = cats(put(year(date2), year2.),"-", put(date2, monname3.));
	year2 = put(year(date2), year.);

	*format date yymon.;
	drop monyear;
run;&lt;/PRE&gt;&lt;P&gt;Here's some sample rows from the input data ("ucd4"):&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dbcrow_0-1681421480373.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82674iCEA37D2F654F982B/image-size/large?v=v2&amp;amp;px=999" role="button" title="dbcrow_0-1681421480373.png" alt="dbcrow_0-1681421480373.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;P&gt;As readily seen, the date variable ("date") maps correctly on to the number of days since Jan 1, 1960:&amp;nbsp; 2016-01-01 is, in fact 20454 days from 1960-01-01.&amp;nbsp; The above code gets the month right, but outputs the year as 1965. Here are some sample rows from the created dataset ("ucd5"):&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dbcrow_1-1681421669440.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82675i18911C8E647308FB/image-size/large?v=v2&amp;amp;px=999" role="button" title="dbcrow_1-1681421669440.png" alt="dbcrow_1-1681421669440.png" /&gt;&lt;/span&gt;&lt;P&gt;Any ideas on what's going on? Since the code outputs 1965 as the year from both the "date" and the "date2" variables, I suspect that the origin date is something other than 1960-01-01. How can I check and, if appropriate, reset the origin date? Or is the problem something else?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 21:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869669#M343517</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2023-04-13T21:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: "PUT" function returning wrong year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869670#M343518</link>
      <description>&lt;PRE&gt;put(year(date2), year2.)&lt;/PRE&gt;
&lt;P&gt;This is incorrect. You take the year (1965) then apply a year format to that date, which is why you're getting 1965&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;put(date2, yymmdd2.) to get just the last two digits.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The year format would be applied to a date variable, not to the year value.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 21:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869670#M343518</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-13T21:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: "PUT" function returning wrong year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869671#M343519</link>
      <description>&lt;P&gt;Many thanks, Reeza. Worked like a charm.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm not sure why: where is the 1965 coming from? It's nowhere in the original data I'm trying to manipulate. Why would year(date2) return 1965 instead of 2016?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update: for some reason, I reran my original code and it's now working fine. So, both the original code and your suggested replacement seem to work. Working with dates in SAS seems unnecessarily difficult! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 21:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869671#M343519</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2023-04-13T21:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: "PUT" function returning wrong year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869672#M343520</link>
      <description>I wouldn't expect your original code to work at all. &lt;BR /&gt;&lt;BR /&gt;So when you take the year of the date, it returns a numeric value 2016. SAS uses that to count the number of days from January 1, 1960. 2016 days from January 1, 1960 ends up somewhere in the year 1965 (2016/365.25 ~5.5). &lt;BR /&gt;&lt;BR /&gt;The year format needs to be applied to a variable with a date format. It takes 1965 to be the date in 1965, not your original date.</description>
      <pubDate>Thu, 13 Apr 2023 21:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869672#M343520</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-13T21:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: "PUT" function returning wrong year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869674#M343521</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
date2=20545;
Actual_SAS_Date = date2;

Year_formatted_as_date = year(date2);
year_formatted_as_num= year(date2);

format Actual_SAS_Date date9. Year_formatted_as_date year. year_formatted_as_num 8.;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Reeza_0-1681423367074.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82676i39005616E4A036F2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Reeza_0-1681423367074.png" alt="Reeza_0-1681423367074.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 22:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869674#M343521</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-13T22:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: "PUT" function returning wrong year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869676#M343522</link>
      <description>&lt;P&gt;Thanks for this explanation, Reeza. I reran the original code and you're right: it wasn't working. I don't know why I thought it was.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, I tender my gratitude for your taking the time to respond.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 22:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-PUT-quot-function-returning-wrong-year/m-p/869676#M343522</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2023-04-13T22:20:44Z</dc:date>
    </item>
  </channel>
</rss>

