<?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: Comparing a date variable to a year, to calculate how many date variables are in this year in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/266004#M57937</link>
    <description>&lt;P&gt;You have surely right, I didn't manage very well "counting" procedures that's why, unfornunately, I make complicate things for "simple" things. Sorry I&amp;nbsp;am still student and didn't practice so much on data procedures... &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; I'm trying to learn by myself &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you all for your advice and taking time for me !&lt;BR /&gt;&lt;BR /&gt;Alison&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Apr 2016 11:03:55 GMT</pubDate>
    <dc:creator>alisondu77</dc:creator>
    <dc:date>2016-04-25T11:03:55Z</dc:date>
    <item>
      <title>Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265982#M57930</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I have a little problem in my script SAS.&lt;/P&gt;&lt;P&gt;I have a starting date (01jan2015), and I add to this date one&amp;nbsp;month eleven&amp;nbsp;times &amp;nbsp;(01jan2015, 01feb2015, ..., 01dec2015).&lt;BR /&gt;There is no problem for that, but after&amp;nbsp;I would like to count how many dates are in&amp;nbsp;2015 or 2014, and i don't succeed... I just have "1" in output for nb_month_2014 and nb_month_2015, which is&amp;nbsp;wrong. I should have :&amp;nbsp;nb_month_2014= 0 and nb_month_2015=12.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_start = "01jan2015"d; 
%let nb_month_2014=0;
%let nb_month_2015=0;
data _null_;
 do i=0 to 11 ;
 	dt=intnx("month",&amp;amp;date_start.,i,'same');
 	if (put(year(dt),z4.)=2014) then %let nb_month_2014 = %eval(&amp;amp;nb_month_2014 + 1) ;
 	if (put(year(dt),z4.)=2015) then %let nb_month_2015 = %eval(&amp;amp;nb_month_2015 + 1) ;
 end;
run;
%put nb_month_2014 = &amp;amp;nb_month_2014. ;
%put nb_month_2015 = &amp;amp;nb_month_2015. ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Thank you for helping me ! and sorry for my poor english !&lt;BR /&gt;&lt;BR /&gt;Alison&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 09:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265982#M57930</guid>
      <dc:creator>alisondu77</dc:creator>
      <dc:date>2016-04-25T09:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265983#M57931</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This happenns beacuse you mix the macro statements within a data step. If you use macro statements/variables why you don't put them in a macro?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 09:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265983#M57931</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-04-25T09:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265985#M57932</link>
      <description>&lt;P&gt;What is it your trying to do. &amp;nbsp;Post test data in the form of a datastep and what you want the output to look like. &amp;nbsp;The reason I ask is because most of this code is not neccessary. &amp;nbsp;If your couting interval's then there are functions for this, I can provide code, but I need to see the data and what the output should look like. &amp;nbsp;In your code you are mixing Macro language and Base SAS code which doesn't work. &amp;nbsp;Macro is text generator, and happens before any code actually runs. &amp;nbsp;Hence the if statements are evaulated out before the code is even passed to the compiler. &amp;nbsp;In almost all instances you will not need to use Macro language, it does have its place, however most tasks can be done directly in Base SAS.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 09:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265985#M57932</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-25T09:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265986#M57933</link>
      <description>&lt;P&gt;Thank you ! So, I should do something like this :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test() ;
%let date_start = "01jan2015"d; 
%let nb_month_2014=0;
%let nb_month_2015=0;
%do i=0 %to 11 ;
 	%let dt=%sysfunc(intnx("month",&amp;amp;date_start.,&amp;amp;i.,'same'));
 	%if put(%sysfunc(year(&amp;amp;dt.),z4.))=2014 %then %let nb_month_2014 = %eval(&amp;amp;nb_month_2014 + 1) ;
 	%if put(%sysfunc(year(&amp;amp;dt.),z4.))=2015  %then %let nb_month_2015 = %eval(&amp;amp;nb_month_2015 + 1) ;
 %end;
%mend ;
%test() 
%put nb_month_2014 = &amp;amp;nb_month_2014. ;
%put nb_month_2015 = &amp;amp;nb_month_2015. ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I don't manage my errors, I am a beginner in macro ... Can you help me to find what's wrong in my script ? Thank you in advance !&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Alison&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 09:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265986#M57933</guid>
      <dc:creator>alisondu77</dc:creator>
      <dc:date>2016-04-25T09:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265988#M57934</link>
      <description>&lt;P&gt;As noted in my post below, this is a very good example of trying to force a very simple Base SAS task through the macro pre-processor which isn't built for writing code.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 09:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265988#M57934</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-25T09:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265990#M57935</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test;&lt;BR /&gt;%let date_start = %sysfunc(inputn(01jan2015,date9.));&lt;BR /&gt;%let nb_month_2014=0;&lt;BR /&gt;%let nb_month_2015=0;&lt;BR /&gt;%do i=0 %to 11;&lt;BR /&gt;&lt;BR /&gt;%let dt=%sysfunc(intnx(month,&amp;amp;date_start.,&amp;amp;i,same));&lt;BR /&gt;%if %sysfunc(year(&amp;amp;dt)) eq 2014 %then %let nb_month_2014 = %eval(&amp;amp;nb_month_2014 + 1) ;&lt;BR /&gt;%if %sysfunc(year(&amp;amp;dt)) eq 2015 %then %let nb_month_2015 = %eval(&amp;amp;nb_month_2015 + 1) ;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;%put nb_month_2014 = &amp;amp;nb_month_2014. ;&lt;BR /&gt;%put nb_month_2015 = &amp;amp;nb_month_2015. ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%mend test;&lt;BR /&gt;&lt;BR /&gt;%test;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 10:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265990#M57935</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-04-25T10:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265995#M57936</link>
      <description>&lt;P&gt;Why are you using macro variables at all?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 10:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/265995#M57936</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-25T10:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/266004#M57937</link>
      <description>&lt;P&gt;You have surely right, I didn't manage very well "counting" procedures that's why, unfornunately, I make complicate things for "simple" things. Sorry I&amp;nbsp;am still student and didn't practice so much on data procedures... &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; I'm trying to learn by myself &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you all for your advice and taking time for me !&lt;BR /&gt;&lt;BR /&gt;Alison&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 11:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/266004#M57937</guid>
      <dc:creator>alisondu77</dc:creator>
      <dc:date>2016-04-25T11:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a date variable to a year, to calculate how many date variables are in this year</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/266010#M57938</link>
      <description>&lt;P&gt;Here is a datastep version, it is deliberately verbose to show the working of the date increment functions. &amp;nbsp;You could even do the same thing for many years, but if you were to do that then either an array, or creating a big output dataset and then aggregate function on it:&lt;/P&gt;
&lt;PRE&gt;%let date_start="01JAN2015"d;
data _null_;
  d=&amp;amp;date_start.;
  do i=0 to 11;
    year2014=sum(year2014,ifn(year(d)=2014,1,0));
    year2015=sum(year2015,ifn(year(d)=2015,1,0));
    d=intnx('month',d,1);
  end;
  put "2014=" year2014 ", 2015=" year2015;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2016 11:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-a-date-variable-to-a-year-to-calculate-how-many-date/m-p/266010#M57938</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-25T11:21:42Z</dc:date>
    </item>
  </channel>
</rss>

