<?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: how to macro a accumulating time period in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307751#M61128</link>
    <description>&lt;P&gt;sorry for confusing, I repost it to clarify.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Oct 2016 19:58:15 GMT</pubDate>
    <dc:creator>zhangda</dc:creator>
    <dc:date>2016-10-27T19:58:15Z</dc:date>
    <item>
      <title>how to macro a accumulating time period</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307713#M61123</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to code a macro to get a column as a time period, which is called wantdate, &amp;nbsp;It is accumulating till today every day. For example, if the startdate=01/01/2016, and enddate=02/27/2016. The wandate should cover the data as wantdate1, which is 01/01/2016, wantdate2, which is betweem&amp;nbsp;01/01/2016 and 01/02/2016, wantdate3, which is between&amp;nbsp;&lt;SPAN&gt;01/01/2016 and 01/03/2016,wantdate4, which is &lt;SPAN&gt;between&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;01/01/2016 and 01/04/2016.....and the last one is wantdate57, which is &amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;between&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;01/01/2016 and 02/27/2016. Is the code below good? If not, how to correct it? Thanks a lot!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let startdate = 01jan2016;&lt;/P&gt;&lt;P&gt;%let enddate = 27feb2016;&lt;/P&gt;&lt;P&gt;*Number of loops;&lt;/P&gt;&lt;P&gt;%let iterations = %sysfunc(intck(day, "&amp;amp;startdate."d, "&amp;amp;enddate."d));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Initialize new date variables four counting;&lt;/P&gt;&lt;P&gt;%let lowerdate = &amp;amp;startdate;&lt;/P&gt;&lt;P&gt;%let upperdate = %sysfunc(intnx(month, "&amp;amp;lowerdate"d, 11, end), date9.);&lt;/P&gt;&lt;P&gt;%put &amp;amp;lowerdate.;&lt;/P&gt;&lt;P&gt;%put &amp;amp;upperdate.;&lt;/P&gt;&lt;P&gt;%put &amp;amp;iterations;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;cases_per_year&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%do i = &lt;STRONG&gt;1&lt;/STRONG&gt; %to &amp;amp;iterations;&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql noprint;*/&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(zip)*/&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; into :nr_obs*/&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; from cases*/&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; where (diagdate GE "&amp;amp;lowerdate"d AND diagdate LE "&amp;amp;upperdate"d);*/&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; run;*/&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *Increment both the lower and the upper boundary of the time interval by one year for the next iteration to count the numbers of the following year and so on;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let lowerdate = %sysfunc( intnx(year, "&amp;amp;lowerdate"d, 1, beginning), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let upperdate = %sysfunc(intnx(year, "&amp;amp;upperdate"d, 1, end), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;lowerdate.;&lt;/P&gt;&lt;P&gt;%put &amp;amp;upperdate.;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; cases_per_year;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;cases_per_year&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 18:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307713#M61123</guid>
      <dc:creator>zhangda</dc:creator>
      <dc:date>2016-10-27T18:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to macro a accumulating time period</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307723#M61124</link>
      <description>&lt;P&gt;I don't think you need a macro and it's probably making your code too complex.&lt;/P&gt;
&lt;P&gt;Can you post sample input data and sample output and explain your logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, do you have SAS/ETS?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 18:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307723#M61124</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-27T18:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to macro a accumulating time period</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307725#M61125</link>
      <description>&lt;P&gt;Since it appears that your data has a date variable then perhaps you would want to look at this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq data=cases;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables diagdate;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; format diagdate yearr4.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or possibly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq data=cases;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables diagnosisvariable * diagdate;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; format diagdate yearr4.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 18:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307725#M61125</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-27T18:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to macro a accumulating time period</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307751#M61128</link>
      <description>&lt;P&gt;sorry for confusing, I repost it to clarify.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 19:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-macro-a-accumulating-time-period/m-p/307751#M61128</guid>
      <dc:creator>zhangda</dc:creator>
      <dc:date>2016-10-27T19:58:15Z</dc:date>
    </item>
  </channel>
</rss>

