<?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: subtract or modity date. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572217#M161474</link>
    <description>Thank you. the simple year=year(caldt); code works!&lt;BR /&gt;It is like a magic!</description>
    <pubDate>Tue, 09 Jul 2019 19:21:55 GMT</pubDate>
    <dc:creator>JKCho</dc:creator>
    <dc:date>2019-07-09T19:21:55Z</dc:date>
    <item>
      <title>subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572195#M161466</link>
      <description>&lt;PRE&gt;length year $ 20;
year=substr(caldt,1,length(caldt)-4;
run;&lt;/PRE&gt;&lt;P&gt;This is the code I used but I am very sure it does not work....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.PNG" style="width: 314px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30888i0A8E22C1031A1A6E/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.PNG" alt="1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I used the code above, it gives me seemingly non-random numbers but not date. like 8778 8782...&lt;/P&gt;&lt;P&gt;Since I have no idea about subtracting across different formats(I know across formats it needs different codes..), I tried many codes but all gave me weird numbers...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I simply want to have is the YEAR part. for example, 19880106 -&amp;gt; 1988&lt;/P&gt;&lt;P&gt;Currently, the original variable's format is YYMMDDN8. and when I use codes I have used so far... the format changed to 8. or 12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I simply get the YEAR part only?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your help a lot!!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 18:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572195#M161466</guid>
      <dc:creator>JKCho</dc:creator>
      <dc:date>2019-07-09T18:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572197#M161467</link>
      <description>Did you check your log? I guarantee there's errors in there. Is your variable numeric or character?&lt;BR /&gt;&lt;BR /&gt;If character, try SUBSTRN () - note the N instead.&lt;BR /&gt;&lt;BR /&gt;year_char = substrn(variable, 1, 4);&lt;BR /&gt;year_num = input(year_char, 4.);</description>
      <pubDate>Tue, 09 Jul 2019 18:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572197#M161467</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-09T18:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572198#M161468</link>
      <description>&lt;P&gt;It would appear that your variable CALDT is an actual integer containing a valid SAS date and formatted with some format that makes it appear to us humans as 19840103. Can you confirm this by running PROC CONTENTS on this data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, to get the year is simple:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year=year(caldt);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In any event, it is highly advised to learn how to treat SAS dates and SAS datetimes and SAS times as numbers (you seem to be treating them as text strings), and so you also need to learn about how to format these date and time and datetime numbers, and how to use simple functions such as YEAR() and MONTH() and INTCK() and INTNX(). If you are going to be dealing with dates in your programs, this seems mandatory to me.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 19:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572198#M161468</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-09T19:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572200#M161470</link>
      <description>&lt;P&gt;I agree.. I have learned statistical analysis using SAS but nothing about data trimming and it is now so demanding.&lt;/P&gt;&lt;P&gt;I am not sure what to tell you...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After PROC CONTENTS. I can see below. CALDT is number in YYMMDD format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Alphabetic List of Variables and Attributes# Variable Type Len Format Informat Label12 &lt;TABLE cellspacing="0" cellpadding="3"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CALDT&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;YYMMDDN8.&lt;/TD&gt;&lt;TD&gt;YYMMDD8.&lt;/TD&gt;&lt;TD&gt;Calendar Date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;SPINDX&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;8.2&lt;/TD&gt;&lt;TD&gt;8.2&lt;/TD&gt;&lt;TD&gt;Level of the S&amp;amp;P 500 Index&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 09 Jul 2019 19:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572200#M161470</guid>
      <dc:creator>JKCho</dc:creator>
      <dc:date>2019-07-09T19:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572203#M161471</link>
      <description>&lt;P&gt;So your PROC CONTENTS confirms what I suspected, and the YEAR function is all you need to obtain the year.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Remember that a formatted date number is still internally to SAS as an integer (which is the number of days since January 1, 1960). It doesn't really matter that us humans see 19840103, SAS thinks it is 8768 and the YEAR function will obtain the year from it. It is harder (and not really worth doing) to extract the year from the formatted number.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 19:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572203#M161471</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-09T19:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572204#M161472</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270067"&gt;@JKCho&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I agree.. I have learned statistical analysis using SAS but nothing about data trimming and it is now so demanding.&lt;/P&gt;
&lt;P&gt;I am not sure what to tell you...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After PROC CONTENTS. I can see below. CALDT is number in YYMMDD format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;Alphabetic List of Variables and Attributes# Variable Type Len Format Informat Label12
&lt;TABLE cellspacing="0" cellpadding="3"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;CALDT&lt;/TD&gt;
&lt;TD&gt;Num&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;YYMMDDN8.&lt;/TD&gt;
&lt;TD&gt;YYMMDD8.&lt;/TD&gt;
&lt;TD&gt;Calendar Date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;SPINDX&lt;/TD&gt;
&lt;TD&gt;Num&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;8.2&lt;/TD&gt;
&lt;TD&gt;8.2&lt;/TD&gt;
&lt;TD&gt;Level of the S&amp;amp;P 500 Index&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As already stated, use the year() function to extract the year from the date.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 19:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572204#M161472</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-09T19:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572205#M161473</link>
      <description>Probably more in depth than you want. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;If your variable is numeric, Paigemiller's solution is your best option.</description>
      <pubDate>Tue, 09 Jul 2019 19:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572205#M161473</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-09T19:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572217#M161474</link>
      <description>Thank you. the simple year=year(caldt); code works!&lt;BR /&gt;It is like a magic!</description>
      <pubDate>Tue, 09 Jul 2019 19:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572217#M161474</guid>
      <dc:creator>JKCho</dc:creator>
      <dc:date>2019-07-09T19:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572218#M161475</link>
      <description>Thank you!</description>
      <pubDate>Tue, 09 Jul 2019 19:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572218#M161475</guid>
      <dc:creator>JKCho</dc:creator>
      <dc:date>2019-07-09T19:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: subtract or modity date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572220#M161476</link>
      <description>Thank you for sharing the link!&lt;BR /&gt;I have to look into it crefully!</description>
      <pubDate>Tue, 09 Jul 2019 19:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtract-or-modity-date/m-p/572220#M161476</guid>
      <dc:creator>JKCho</dc:creator>
      <dc:date>2019-07-09T19:22:47Z</dc:date>
    </item>
  </channel>
</rss>

