<?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: Create a monthly end date between year in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859105#M339447</link>
    <description>&lt;P&gt;Thanks for the correction. I modified the code and it worked. As seen in the final output I'm trying to count number of cases present on the point in time date each month from start year to end year. I think it can be more neat (eg the PIT is date formatted as an input value) or more flexible (e.g. allowing to chose end of month as supposedly I should count cases from start of month to end of month, not on the 1st or last date of a month e.g. the 31th). But it does the job so I can get going, so it's much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; input ID @3 start date9. @13 end date9.;
	format start end yymmdd10.;
datalines;
1 27JAN2018	06MAY2019 
2 05MAR2019	09MAR2020
3 31OCT2017	03NOV2019
4 15JAN2018	19JAN2020
5 04JUL2015	12JUL2020
;
run;
%macro get;
%do year=2018 %to 2020;
%do month=1 %to 12;
%let PIT=%sysfunc(mdy(&amp;amp;month,1,&amp;amp;year)); /*point in time date at start of each month*/
proc sql; create table want&amp;amp;year&amp;amp;month as
  SELECT id, put(&amp;amp;pit, yymmdd10.) as PIT, start, end 
  FROM have
  where (start &amp;lt;= &amp;amp;PIT and start is not NULL) AND (END&amp;gt; &amp;amp;PIT OR END IS NULL);
quit;
%end;
%end;
%mend;
%get;
data comb; set want2018: want2019: want2020:; run;
*Count # of cases for each PIT date;
proc sql; create table prevalence_cases as select PIT, count(*) as Prevalence_cases from comb group by 1; quit;
*Create dummy date for each month;
data dummy; 
	do date='01jan2018'd to '31dec2020'd;
	*PIT=put(intnx('month',date,0,'E'), yymmdd10.); /*end of month*/
	PIT=put(intnx('month',date,0), yymmdd10.); /*start of month*/
	output;
	end;
run;
proc sort data=dummy (drop=date) nodupkey; by PIT; run;
data final; merge dummy (in=a) prevalence_cases (in=b); by PIT; 
if a and not b then Prevalence_cases=0;
run;
proc print noobs; run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output is as the following.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 26.25pt;"&gt;
&lt;TD width="64" height="35" class="xl64" style="height: 26.25pt; width: 48pt;"&gt;PIT&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="width: 48pt;"&gt;Prevalence_cases&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;1/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;2/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;3/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;4/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;5/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;6/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;7/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;8/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;9/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;10/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;11/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;12/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;1/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;2/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;3/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;4/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;5/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;6/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;7/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;8/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;9/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;10/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;11/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;12/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;1/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;2/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;3/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;4/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;5/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;6/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;7/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;8/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;9/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;10/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;11/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;12/1/2020&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Thu, 16 Feb 2023 04:10:03 GMT</pubDate>
    <dc:creator>Solph</dc:creator>
    <dc:date>2023-02-16T04:10:03Z</dc:date>
    <item>
      <title>Create a monthly end date between year in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859090#M339440</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to run a DO LOOP in a macro where my data run is based on a point in time date at end of month each month say between 2018 and 2020 (so I'd run 12mo * 3 yrs=36 times). That is is the person is present at end of month each month based on the start date and end date of the data.&lt;/P&gt;
&lt;P&gt;All I could come up with is such as the following. And apparently I wasn't able to apply end of month, so I just conveniently settled with first day of each month (that is if end of month isn't possible, I'm OK with first date of each month).&amp;nbsp;&amp;nbsp;Much appreciated for any help you can give me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get;
%do year=2018 %to 2020;
%do month=1 %to 12;
%let PIT=%eval(mdy(month,1,&amp;amp;year));
proc sql; create table want&amp;amp;PIT as
  SELECT var1, var2 
  FROM have
  where (start &amp;lt;= "&amp;amp;PIT"d and start is not NULL) AND (END&amp;gt; "&amp;amp;PIT"d OR END IS NULL);
quit;
%end;
%end;
%mend;&lt;BR /&gt;%get;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the sample data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; input ID @3 start date9. @13 end date9.;
	format start end yymmdd10.;
datalines;
1 27JAN2018	06MAY2019 
2 05MAR2019	09MAR2020
3 31OCT2017	03NOV2019
4 15JAN2018	19JAN2020
5 04JUL2015	12JUL2020
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW this code below would give me end of month but I'm running each date between two dates so I couldn't really apply (not to mention it won't work in a macro environment.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy; 
	do date='01jan2018'd to '31dec2020'd;
	Month_EndDate=put(intnx('month',date,0,'E'), yymmdd10.);
	output;
	end;
run;
proc sort data=dummy (drop=date) nodupkey; by Month_EndDate; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 03:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859090#M339440</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2023-02-16T03:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create a monthly end date between year in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859093#M339441</link>
      <description>&lt;P&gt;How about showing explicit values that you do want to use for an end comparison?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since MDY is used to make &amp;amp;PIt returns a date value you do not want to use "&amp;amp;pit"d to compare a value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you run your macro with the option MPRINT set to see what your code is generating?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 01:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859093#M339441</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-16T01:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create a monthly end date between year in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859095#M339442</link>
      <description>&lt;P&gt;Error messages in the log are&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Required operator not found in expression: mdy(month,1,2018) 
ERROR: The macro GET will stop executing.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The HAVE data should be such as the following for three 3 dates Jan 31, 2028, Dec 31, 2019 and June 30, 2020&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;For PIT=01JAN2018, 2 cases met the criteria present on Jan 1, 2018
   3 31OCT2017	03NOV2019
   5 04JUL2015	12JUL2020
For PIT=01DEC2019, 3 cases met the criteria present on Dec 1, 2019
   2 05MAR2019	09MAR2020
   4 15JAN2018	19JAN2020
   5 04JUL2015	12JUL2020
For PIT=01JUN2020, 1 case met the criteria present on June 1, 2020
   5 04JUL2015	12JUL2020
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Feb 2023 04:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859095#M339442</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2023-02-16T04:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a monthly end date between year in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859098#M339443</link>
      <description>&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;%do month=1 %to 12;
%let PIT=%sysfunc(mdy(&lt;STRONG&gt;&lt;FONT size="6"&gt;&amp;amp;&lt;/FONT&gt;&lt;/STRONG&gt;month,1,&amp;amp;year));&lt;/PRE&gt;
&lt;P&gt;You need to use %sysfunc to call a data step function, not %eval. You also need to make sure you have the &amp;amp; to reference the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am still not able to follow the logic of what value you want to use for for an upper bound for a given starting PIT value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 02:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859098#M339443</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-16T02:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a monthly end date between year in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859105#M339447</link>
      <description>&lt;P&gt;Thanks for the correction. I modified the code and it worked. As seen in the final output I'm trying to count number of cases present on the point in time date each month from start year to end year. I think it can be more neat (eg the PIT is date formatted as an input value) or more flexible (e.g. allowing to chose end of month as supposedly I should count cases from start of month to end of month, not on the 1st or last date of a month e.g. the 31th). But it does the job so I can get going, so it's much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; input ID @3 start date9. @13 end date9.;
	format start end yymmdd10.;
datalines;
1 27JAN2018	06MAY2019 
2 05MAR2019	09MAR2020
3 31OCT2017	03NOV2019
4 15JAN2018	19JAN2020
5 04JUL2015	12JUL2020
;
run;
%macro get;
%do year=2018 %to 2020;
%do month=1 %to 12;
%let PIT=%sysfunc(mdy(&amp;amp;month,1,&amp;amp;year)); /*point in time date at start of each month*/
proc sql; create table want&amp;amp;year&amp;amp;month as
  SELECT id, put(&amp;amp;pit, yymmdd10.) as PIT, start, end 
  FROM have
  where (start &amp;lt;= &amp;amp;PIT and start is not NULL) AND (END&amp;gt; &amp;amp;PIT OR END IS NULL);
quit;
%end;
%end;
%mend;
%get;
data comb; set want2018: want2019: want2020:; run;
*Count # of cases for each PIT date;
proc sql; create table prevalence_cases as select PIT, count(*) as Prevalence_cases from comb group by 1; quit;
*Create dummy date for each month;
data dummy; 
	do date='01jan2018'd to '31dec2020'd;
	*PIT=put(intnx('month',date,0,'E'), yymmdd10.); /*end of month*/
	PIT=put(intnx('month',date,0), yymmdd10.); /*start of month*/
	output;
	end;
run;
proc sort data=dummy (drop=date) nodupkey; by PIT; run;
data final; merge dummy (in=a) prevalence_cases (in=b); by PIT; 
if a and not b then Prevalence_cases=0;
run;
proc print noobs; run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output is as the following.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 26.25pt;"&gt;
&lt;TD width="64" height="35" class="xl64" style="height: 26.25pt; width: 48pt;"&gt;PIT&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="width: 48pt;"&gt;Prevalence_cases&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;1/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;2/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;3/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;4/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;5/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;6/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;7/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;8/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;9/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;10/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;11/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;12/1/2018&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;1/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;2/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;3/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;4/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;5/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;6/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;7/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;8/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;9/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;10/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;11/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;12/1/2019&lt;/TD&gt;
&lt;TD class="xl66"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;1/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;2/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;3/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;4/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;5/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;6/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;7/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;8/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;9/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;10/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl67" style="height: 15.75pt;"&gt;11/1/2020&lt;/TD&gt;
&lt;TD class="xl66"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;12/1/2020&lt;/TD&gt;
&lt;TD class="xl63"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 16 Feb 2023 04:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859105#M339447</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2023-02-16T04:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create a monthly end date between year in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859110#M339450</link>
      <description>&lt;P&gt;You are looping in the wrong place. For each observations update the count for the months it contains.&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  input ID start :date. end :date.;
  format start end yymmdd10.;
datalines;
1 27JAN2018	06MAY2019 
2 05MAR2019	09MAR2020
3 31OCT2017	03NOV2019
4 15JAN2018	19JAN2020
5 04JUL2015	12JUL2020
;

%let start="01JAN2018"d;
%let end="31DEC2020"d;
%let nmonths=%sysfunc(intck(month,&amp;amp;start,&amp;amp;end));
data count;
  array months[0:&amp;amp;nmonths] _temporary_ (0 &amp;amp;nmonths*0) ;
  set have end=eof;
  do month=intck('month',&amp;amp;start,max(&amp;amp;start,start)) to intck('month',&amp;amp;start,min(end,&amp;amp;end));
    months[month]+1;
  end;
  if eof then do month=0 to &amp;amp;nmonths;
    PIT=put(intnx('month',&amp;amp;start,month),yymm7.);
    count=months[month];
    output;
  end;
  keep pit count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs      PIT      count

  1    2018M01      4
  2    2018M02      4
  3    2018M03      4
  4    2018M04      4
  5    2018M05      4
  6    2018M06      4
  7    2018M07      4
  8    2018M08      4
  9    2018M09      4
 10    2018M10      4
 11    2018M11      4
 12    2018M12      4
 13    2019M01      4
 14    2019M02      4
 15    2019M03      5
 16    2019M04      5
 17    2019M05      5
 18    2019M06      4
 19    2019M07      4
 20    2019M08      4
 21    2019M09      4
 22    2019M10      4
 23    2019M11      4
 24    2019M12      3
 25    2020M01      3
 26    2020M02      2
 27    2020M03      2
 28    2020M04      1
 29    2020M05      1
 30    2020M06      1
 31    2020M07      1
 32    2020M08      0
 33    2020M09      0
 34    2020M10      0
 35    2020M11      0
 36    2020M12      0

&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Feb 2023 04:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859110#M339450</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-16T04:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a monthly end date between year in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859240#M339493</link>
      <description>&lt;P&gt;Thanks Tom. I ran your code but it is returning&amp;nbsp; with value 2 for all years and months. But if I change your data input lines to the original code as below, then it's fine. Not sure why or if it matters. Your code indeed is doing the job of being present any time in a given month based on individual's start and end dates. Thanks again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; input ID @3 start date9. @13 end date9.;
	format start end yymmdd10.;
datalines;
1 27JAN2018	06MAY2019 
2 05MAR2019	09MAR2020
3 31OCT2017	03NOV2019
4 15JAN2018	19JAN2020
5 04JUL2015	12JUL2020
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 17:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859240#M339493</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2023-02-16T17:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create a monthly end date between year in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859244#M339496</link>
      <description>&lt;P&gt;If you had to modify the INPUT statement to that code with&amp;nbsp;@ pointers and fixed format input instead of normal LIST MODE input then either your actual data lines have TABS or other strange characters instead of spaces (Which is why jumping over them with&amp;nbsp;@ worked) or you have some missing values that are not demarked with a period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you are using Display Manager to edit and submit code then the tabs in the data lines will automatically be replaced by spaces.&amp;nbsp; But if you are using SAS/Studio to submit the code then this does not happen and you end up with actual TAB characters in the data lines.&amp;nbsp; You can tell SAS/Studio editor not to insert actual&amp;nbsp;TAB characters into the file by changing your preferences.&amp;nbsp; You can still hit the TAB key to indent your code, but it will just insert the proper number of spaces to move to the next tab stop instead of messing up your code file with embedded tabs.&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="Tom_0-1676570497953.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80476i0F26C3ACF5C8C17A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1676570497953.png" alt="Tom_0-1676570497953.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;This data step will work (note there is no need to add an extra RUN statement after the end of the data step).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  input ID start :date. end :date.;
  format start end yymmdd10.;
datalines;
1 27JAN2018 06MAY2019 
2 .         09MAR2020
3 31OCT2017 03NOV2019
4 15JAN2018 .
5 04JUL2015 12JUL2020
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But data lines with only spaces will NOT work with list mode input since the INPUT statement will go hunting for a value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  input ID start :date. end :date.;
  format start end yymmdd10.;
datalines;
1 27JAN2018 06MAY2019 
2           09MAR2020
3 31OCT2017 03NOV2019
4 15JAN2018  
5 04JUL2015 12JUL2020
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 18:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-monthly-end-date-between-year-in-a-macro/m-p/859244#M339496</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-16T18:02:11Z</dc:date>
    </item>
  </channel>
</rss>

