<?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: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164706#M31852</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand that you can't provide the real data but try to mock-up some representative sample data (a data step creating such data) and then explain us how the expected result should look like. Without such sample data you can see that people answering your questions need to make assumptions like you having patient id's in your data and the like. It's much better and easier for us if you provide some data - and it's better for you as then you will get answers and code which are actually fit for your real data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure if below sample data is representative for what you have. May be the code will still be helpful for you. Assuming that you're rather new to SAS coding I've tried to only use simple data step processing to get to the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input patient_id $ zip_code $ date:date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format date date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;1 1234 01jun2011&lt;/P&gt;&lt;P&gt;1 1234 01jan2012&lt;/P&gt;&lt;P&gt;1 1234 15dec2011&lt;/P&gt;&lt;P&gt;1 1234 10may2013&lt;/P&gt;&lt;P&gt;2 1234 01feb2012&lt;/P&gt;&lt;P&gt;2 1234 15dec2011&lt;/P&gt;&lt;P&gt;3 5678 15dec2011&lt;/P&gt;&lt;P&gt;3 5678 10may2013&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data inter;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; year=year(date);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=inter;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by zip_code patient_id year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(keep=zip_code year count);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set inter;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by zip_code patient_id year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.patient_id then count+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last.zip_code then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Dec 2014 23:38:38 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2014-12-29T23:38:38Z</dc:date>
    <item>
      <title>Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164698#M31844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to get right to the point, here's my problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset with hundreds of cases of people afftected by a certain disease, this dataset is simply called 'cases'. Every observation/person within this dataset has variables like zip code ('zip') and the date of diagnosis ('diagdate'), which defines when a person (observation) fell ill - VERY IMPORTANT FOR MY TASK.&lt;/P&gt;&lt;P&gt;These dates of diagnosis range from early 2006 till today. So every observation/case in this dataset IS sick, it's only a matter of time, WHEN they became sick! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I wanted to do then was to count the number of cases/people who fell sick "for the first time" (they stay sick of course) for every SINGLE year within the time period from the beginning of 2009 till the end of 2013.&lt;/P&gt;&lt;P&gt;Why do I want to do that? &lt;/P&gt;&lt;P&gt;--&amp;gt; To see if there are any trends over time from 2009 to 2013, if the number of sick people increases/decreases or doesn't change year by year. Of course, it gets more complicated, but for now I only need the numbers for every year. &lt;/P&gt;&lt;P&gt;(E.g., 123 cases in 2009, 145 cases in 2010, 131 cases in 2011, 172 cases in 2012...hypotheticalyl)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wanted to accomplish that by using a Macro that loops through every year of this time interval. Part of this Macro is an SQL query that simply counts the observations that fell sick within this certain year (first 2009, then 2010, 2011 and so on).&lt;/P&gt;&lt;P&gt;This again done by counting the variable 'zip' (no missing values, so it works for receiving a valid number) where an observation's date of diagnosis is between the 1st January of this year (e.g. 1st January 2009) and the 31st December of the same year (31st December 2009, respectively). &lt;/P&gt;&lt;P&gt;And the same for the next year, and the year after and so on. &lt;/P&gt;&lt;P&gt;And then print these numbers. This Macro is part of a more complicated program which is working without any errors so far. However...the counting macro doesn't work. I'm pretty sure there are several mistakes (I read of this %sysfunc thing...but I have NO clue how it really works...) and I JUST realized another one, but I just can't put it together correctly right now. I'd love to get some ideas/help how to fix this or even find a simpler/better solution for this problem...&lt;/P&gt;&lt;P&gt;Here's the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;*I created these macro variables way earlier in the code to get rid of all the other observations outside of this time interval 2009-2013 by creating a dataset only with those observations whose date of diagnosis&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;was between 'startdate' and 'enddate' - I can't get rid of these global macro variables&lt;/SPAN&gt;&lt;SPAN style="color: #99cc00;"&gt;&lt;SPAN style="color: #008000;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%let&lt;/SPAN&gt; startdate = 01jan2009;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%let&lt;/SPAN&gt; enddate = 31dec2013;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;*Number of loops;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%let&lt;/SPAN&gt; iterations = round(((&lt;SPAN style="color: #00ccff;"&gt;"&amp;amp;enddate"d&lt;/SPAN&gt; - &lt;SPAN style="color: #00ccff;"&gt;"&amp;amp;startdate"d&lt;/SPAN&gt;)/365.25), 1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;*Initialize new date variables four counting;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%let&lt;/SPAN&gt; lowerdate = &amp;amp;startdate; &lt;SPAN style="color: #008000;"&gt;= 1st January 2009&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%let&lt;/SPAN&gt; upperdate = intnx('month', "&amp;amp;lowerdate"d, 11, 'end'); &lt;SPAN style="color: #008000;"&gt;= 31st December 2009&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333300;"&gt;%macro cases_per_year;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%do&lt;/SPAN&gt; i = 1 &lt;SPAN style="color: #3366ff;"&gt;%to&lt;/SPAN&gt; &amp;amp;iterations;&lt;/P&gt;&lt;P&gt;&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 &lt;SPAN style="color: #00ccff;"&gt;"&amp;amp;lowerdate"d&lt;/SPAN&gt; AND diagdate LE &lt;SPAN style="color: #00ccff;"&gt;"&amp;amp;upperdate"d&lt;/SPAN&gt;);&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;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #008000;"&gt;*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;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;lowerdate = intnx('year', &lt;SPAN style="color: #00ccff;"&gt;"&amp;amp;lowerdate"d&lt;/SPAN&gt;, 1, 'beginning'); = &lt;SPAN style="color: #008000;"&gt;1st January 2010&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;upperdate = intnx('year', &lt;SPAN style="color: #00ccff;"&gt;"&amp;amp;upperdate"d&lt;/SPAN&gt;, 1, 'end'); &lt;SPAN style="color: #008000;"&gt;= 31st December 2010&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%put&lt;/SPAN&gt; &amp;amp;nr_obs;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%end&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333300;"&gt;%mend cases_per_year;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333300;"&gt;%cases_per_year;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I run the code, everything works flawlessly, the creation of the cases dataset, some other calculations I've done before on these data etc... only in the end SAS is complaining about the macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; is required. The condition was: &amp;amp;iterations&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;ERROR: The macro CASES_PER_YEAR will stop executing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ANY HELP is greatly appreciated! This thing makes me go crazy!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Post changed 12/29/2014 - 10.22pm&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 17:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164698#M31844</guid>
      <dc:creator>SoftDrink</dc:creator>
      <dc:date>2014-12-29T17:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164699#M31845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't need a macro for this. Once a person has a disease they have it forever or is there an end date? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 19:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164699#M31845</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-12-29T19:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164700#M31846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the question?&lt;/P&gt;&lt;P&gt;- number of person in each year (new cases and cured/ended-out of registration). this requires a step for unique ditstinct of every person.&amp;nbsp; &lt;/P&gt;&lt;P&gt;- the date can be formatted for you or anay period to report on. By that you can use one of the many reporting/displaying options (procs).&lt;/P&gt;&lt;P&gt;I cannot see how the code you have started with could be helpful.&lt;/P&gt;&lt;P&gt;Just restart the formulating the wanted (not too detailed) result and the dat you are having as the origin to start with.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 20:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164700#M31846</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-12-29T20:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164701#M31847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm assuming you have an ID variable for each case&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data case_yearly;&lt;/P&gt;&lt;P&gt;set cases;&lt;/P&gt;&lt;P&gt;do year=year(diagdate) to year(&amp;amp;enddate.);&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;keep year zip id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then run a proc freq on the output dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding your code:&lt;/P&gt;&lt;P&gt;You can't use functions in macro code, except with the use of %sysfunc. This is so you can explicitly tell the macro/SAS what is text and what is a function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, here's how your macro would work, if you still wanted to go that route. I commented out the proc sql section as I didn't have data to test with.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%let&lt;/SPAN&gt; startdate = 01jan2009;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%let&lt;/SPAN&gt; enddate = 31dec2013;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;*Number of loops;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%let&lt;/SPAN&gt; iterations = &lt;SPAN style="color: #0433ff;"&gt;%sysfunc&lt;/SPAN&gt;(intck(year, "&amp;amp;startdate."d, "&amp;amp;enddate."d));&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;means&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;data&lt;/SPAN&gt;=sashelp.class; &lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;*Initialize new date variables four counting;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%let&lt;/SPAN&gt; lowerdate = &amp;amp;startdate;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%let&lt;/SPAN&gt; upperdate = &lt;SPAN style="color: #0433ff;"&gt;%sysfunc&lt;/SPAN&gt;(intnx(month, "&amp;amp;lowerdate"d, 11, end), date9.);&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%put&lt;/SPAN&gt; &amp;amp;lowerdate.;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%put&lt;/SPAN&gt; &amp;amp;upperdate.;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%put&lt;/SPAN&gt; &amp;amp;iterations;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;STRONG&gt;&lt;EM&gt;cases_per_year&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%do&lt;/SPAN&gt; i = &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;%to&lt;/SPAN&gt; &amp;amp;iterations;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql noprint;*/&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(zip)*/&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; into :nr_obs*/&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; from cases*/&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&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 style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; run;*/&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #008f00;"&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;*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 style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0433ff;"&gt;%let&lt;/SPAN&gt; lowerdate = &lt;SPAN style="color: #0433ff;"&gt;%sysfunc&lt;/SPAN&gt;( intnx(year, "&amp;amp;lowerdate"d, 1, beginning), date9.);&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0433ff;"&gt;%let&lt;/SPAN&gt; upperdate = &lt;SPAN style="color: #0433ff;"&gt;%sysfunc&lt;/SPAN&gt;(intnx(year, "&amp;amp;upperdate"d, 1, end), date9.);&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%put&lt;/SPAN&gt; &amp;amp;lowerdate.;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%put&lt;/SPAN&gt; &amp;amp;upperdate.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #0433ff;"&gt;%end&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/SPAN&gt; cases_per_year;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;%&lt;STRONG&gt;&lt;EM&gt;cases_per_year&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 21:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164701#M31847</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-12-29T21:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164702#M31848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your reply! I edited my initial posting...maybe it's easier to understand now, what I want to do and what I have. The original dataset is HUGE, lots of other variables...most importantly, it's real patient data, so I can't show/upload it here without editing it/dropping other variables, which is what I might do, taking a screenshot or so...so you can better see for yourself. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 21:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164702#M31848</guid>
      <dc:creator>SoftDrink</dc:creator>
      <dc:date>2014-12-29T21:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164703#M31849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can run a proc freq on your data by applying a format to your diagnosis date. &lt;/P&gt;&lt;P&gt;How big is 'big'? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc freq data=cases;&lt;/P&gt;&lt;P&gt;table diagdate/out=yearly_diagnosis;&lt;/P&gt;&lt;P&gt;format diagdate year4.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 21:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164703#M31849</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-12-29T21:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164704#M31850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, too, for your ideas! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; Especially the one with your edited code sample seems to be helpful. However, I just took a quick glimpse at it...I'm done for today. I will dig into that tomorrow and let you know how far I got...for sure.&lt;BR /&gt;And 'big'...well, for my work as a student it's big. ~ 1100 observations, ~ 250 variables (most of them not necessary for me tbh, so I'll drop them anyway).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 21:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164704#M31850</guid>
      <dc:creator>SoftDrink</dc:creator>
      <dc:date>2014-12-29T21:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164705#M31851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A nice small dataset not trouble with computer resources (that is what I care for when it is big).&lt;/P&gt;&lt;P&gt;So far I understand:&amp;nbsp; &lt;/P&gt;&lt;P&gt;- first step reduce dataset to only records having that first notion of becoming ill&lt;/P&gt;&lt;P&gt;&amp;nbsp; (the lowest day date for each person)&amp;nbsp; Do you have an id for each person?&lt;/P&gt;&lt;P&gt;- second step the reporting eg The proc freq on that reduced dataset.&amp;nbsp; &lt;BR /&gt;(done today too, samples when needed to be continued)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 22:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164705#M31851</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-12-29T22:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164706#M31852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand that you can't provide the real data but try to mock-up some representative sample data (a data step creating such data) and then explain us how the expected result should look like. Without such sample data you can see that people answering your questions need to make assumptions like you having patient id's in your data and the like. It's much better and easier for us if you provide some data - and it's better for you as then you will get answers and code which are actually fit for your real data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure if below sample data is representative for what you have. May be the code will still be helpful for you. Assuming that you're rather new to SAS coding I've tried to only use simple data step processing to get to the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input patient_id $ zip_code $ date:date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format date date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;1 1234 01jun2011&lt;/P&gt;&lt;P&gt;1 1234 01jan2012&lt;/P&gt;&lt;P&gt;1 1234 15dec2011&lt;/P&gt;&lt;P&gt;1 1234 10may2013&lt;/P&gt;&lt;P&gt;2 1234 01feb2012&lt;/P&gt;&lt;P&gt;2 1234 15dec2011&lt;/P&gt;&lt;P&gt;3 5678 15dec2011&lt;/P&gt;&lt;P&gt;3 5678 10may2013&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data inter;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; year=year(date);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=inter;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by zip_code patient_id year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(keep=zip_code year count);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set inter;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by zip_code patient_id year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.patient_id then count+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last.zip_code then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Dec 2014 23:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164706#M31852</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-12-29T23:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164707#M31853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understood what you mean, Why not simply make a year variable and count obs by it ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp; year(&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;diagdate&lt;/SPAN&gt;) as year,count(zip) as count&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from cases&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by calculated year;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2014 06:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164707#M31853</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-12-30T06:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164708#M31854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again Reeza, your code example helped me fix the errors mine had! It's working now, I only adapted your changes, the PROC SQL section was already correct. &lt;BR /&gt;And thanks to you, Xia Keshan, too, your solution was definitely less complicated than mine and even lets me reuse the numbers easily since they are in a new dataset. Pretty useful. I wonder why I came up with the macro...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Still...I have another question regarding my macro approach, or rather several connected ones, just for my personal interest:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The thing is...I'm writing this program to be able to manually choose a variable number of years before I run the program, that's why I created the global macro variables 'startdate' and 'enddate'. The dataset with all the cases will be updated the next years, so there will be added more and more cases in the future. The program will then cut down the original complete dataset of cases to only the ones I actually want to have for calculations or counting their numbers, which works fine at the moment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see, I wanted to write the counted numbers of cases into a macro variable called 'nr_obs'.&lt;BR /&gt;How could I create a VARIABLE number of macro variables depending on the actual number of years in my time interval, whereas every macro variable ONLY contains the number of cases of ONE YEAR?&lt;BR /&gt;So, for example, in this case, the time interval is 5 years wide: 2009, 2010, 2011, 2012, 2013.&lt;BR /&gt;The macro 'cases_per_year' should then create 5 different macro variables, like nr_obs1 (contains #cases 2009), nr_obs2 (contains #cases 2010), ... and so on.&lt;BR /&gt;And on top of that, how could I 'transport' these macro variables out of the macro itself, maybe into a dataset or make them global, so I can reuse them later on...because right now, they're just local macro variables, right?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Phew...again, I demand a lot, but If I try to find this out on my own and look all this up, I'll spend hours and hours on it and probably still not get it to work I guess...whereas the things you told me were instantly clear to me.&lt;BR /&gt;So I would be really happy, if you maybe could expand Reeza's working code snippet and kind of show me how to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And by the way, I created a sample case dataset and took a screenshot of it. Maybe this helps. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Posting edited - 12/30/2014 - 2.50pm&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/11058i642333BAE1FAE675/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="cases_example.JPG" title="cases_example.JPG" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2014 13:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164708#M31854</guid>
      <dc:creator>SoftDrink</dc:creator>
      <dc:date>2014-12-30T13:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Count #obs over certain time period within macro (PROC SQL, IntNx, Do To)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164709#M31855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I strongly recommend against your macro approach. It's a sledgehammer for a staple.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can filter your years using either the proc freq or proc SQL method with a WHERE clause. This would also give you your dataset without the need to store your macro variables somewhere. Not to mention speed and clarity when editing your code for the future. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;create table yearly_diagnosis1 as &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp; year(&lt;SPAN style="font-style: inherit;"&gt;diagdate&lt;/SPAN&gt;) as year,count(zip) as count&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from cases&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; &lt;STRONG&gt;where calculated year between year("&amp;amp;startdate"d) and year("&amp;amp;enddate"d)&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by calculated year;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;OR&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Proc freq data=cases noprint;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; where calculated year between year("&amp;amp;startdate"d) and year("&amp;amp;enddate"d)&lt;/SPAN&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;table diagdate*zip/out=yearly_diagnosis2;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;format diagdate year4.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;To your question of how to store macro variables and append them, again a sledgehammer approach. I'd create a data set each loop and append it to the final data set and not go into macro variables at all.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;How would you know that nr_obs1 was aligned with year 2009? You'd have to do a calculation on the date to obtain that. &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;If you really wanted you could do something like the following at the end of your loop, but&amp;nbsp; before you exit the macro:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;data want;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;%do&lt;/SPAN&gt; i = &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;%to&lt;/SPAN&gt; &amp;amp;iterations;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;year=year(&lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;"&amp;amp;startdate"d&lt;/STRONG&gt;&lt;/SPAN&gt;)+&amp;amp;i-1;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;Cases=&amp;amp;&amp;amp;&amp;amp;nr_obs&amp;amp;&lt;SPAN style="color: #009193;"&gt;i.&lt;/SPAN&gt;;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;output;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #0433ff;"&gt;%end&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2014 20:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-obs-over-certain-time-period-within-macro-PROC-SQL-IntNx/m-p/164709#M31855</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-12-30T20:01:16Z</dc:date>
    </item>
  </channel>
</rss>

