<?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: Calculating Indian financial quarter from given date using user-defined function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323632#M271234</link>
    <description>&lt;P&gt;Well, that example is incorrect. &amp;nbsp;You are taking the month number from 12DEC09, and putting that into the variable TT. &amp;nbsp;Then you call you function with this variable, hence you are calling as:&lt;/P&gt;
&lt;P&gt;tempvar=finquart(12);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in your function, you are using the month() function which expects a date (which is a number of days since a certain date), and are passing it 12, which SAS takes as a date number (formatted would be 13JAN1960), and Jan which is month 1 comes out as QTR=4. &amp;nbsp;So correct to this:&lt;/P&gt;
&lt;PRE&gt;options cmplib=twolevel.name;
data temp;
  tt = month('12DEC09'd);
  put tt;
  actual_date_variable='12DEC09'd;
  tempvar = FinQuart(actual_date_value);
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Jan 2017 14:28:26 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-01-10T14:28:26Z</dc:date>
    <item>
      <title>Calculating Indian financial quarter from given date using user-defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323600#M271230</link>
      <description>&lt;P&gt;I wanted to calculate the Indian financial quarter which starts in April (April-Jun would be 1st Qtr). I created a user defined function using the proc fcmp procedure yet it is not giving me the correct answer. What is wrong with my logic?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc fcmp outlib=three.level.name;&lt;BR /&gt;function FinQuart(dat);&lt;BR /&gt;if month(dat) in(4,5,6) then qurt = 1;&lt;BR /&gt;if month(dat) in(7,8,9) then qurt = 2;&lt;BR /&gt;if month(dat) in(10,11,12) then qurt = 3;&lt;BR /&gt;if month(dat) in(1,2,3) then qurt = 4;&lt;BR /&gt;return (qurt);&lt;BR /&gt;endsub;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function returns 4 whatever value you submit.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 12:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323600#M271230</guid>
      <dc:creator>krzy32</dc:creator>
      <dc:date>2017-01-10T12:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Indian financial quarter from given date using user-defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323606#M271231</link>
      <description>&lt;P&gt;Please post test data in the form of a datastep. &amp;nbsp;Personally I would write a datastep to do this, you can then easily debug it and save it for later or put it in a macro if needed. &amp;nbsp;Compiled functions whilst a nice gimmick, are hard to use, proprietary, and obfuscated.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 13:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323606#M271231</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-10T13:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Indian financial quarter from given date using user-defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323609#M271232</link>
      <description>&lt;P&gt;I was testing the function in a datastep itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options cmplib=twolevel.name;&lt;BR /&gt;data temp;&lt;BR /&gt;tt = month('12DEC09'd);&lt;BR /&gt;put tt;&lt;BR /&gt;tempvar = FinQuart(tt);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output&lt;/P&gt;&lt;P&gt;tt &amp;nbsp; &amp;nbsp;tempvar&lt;/P&gt;&lt;P&gt;12 &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 13:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323609#M271232</guid>
      <dc:creator>krzy32</dc:creator>
      <dc:date>2017-01-10T13:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Indian financial quarter from given date using user-defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323628#M271233</link>
      <description>&lt;P&gt;A custom function is good, but you can also use a nested function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quarter = qtr(intnx('month', date, -3, 'b'));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you set the cmplib value?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Options cmplib=...?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 14:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323628#M271233</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-10T14:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Indian financial quarter from given date using user-defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323632#M271234</link>
      <description>&lt;P&gt;Well, that example is incorrect. &amp;nbsp;You are taking the month number from 12DEC09, and putting that into the variable TT. &amp;nbsp;Then you call you function with this variable, hence you are calling as:&lt;/P&gt;
&lt;P&gt;tempvar=finquart(12);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in your function, you are using the month() function which expects a date (which is a number of days since a certain date), and are passing it 12, which SAS takes as a date number (formatted would be 13JAN1960), and Jan which is month 1 comes out as QTR=4. &amp;nbsp;So correct to this:&lt;/P&gt;
&lt;PRE&gt;options cmplib=twolevel.name;
data temp;
  tt = month('12DEC09'd);
  put tt;
  actual_date_variable='12DEC09'd;
  tempvar = FinQuart(actual_date_value);
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jan 2017 14:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323632#M271234</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-10T14:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Indian financial quarter from given date using user-defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323716#M271235</link>
      <description>&lt;P&gt;I can't believe I made such a silly mistake. Thanks a lot. Yes, I have specified the cmplib option. I am new to SAS so I had no idea about nested functions. Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 17:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Indian-financial-quarter-from-given-date-using-user/m-p/323716#M271235</guid>
      <dc:creator>krzy32</dc:creator>
      <dc:date>2017-01-10T17:25:16Z</dc:date>
    </item>
  </channel>
</rss>

