<?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: re: counting days between two dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746124#M234025</link>
    <description>&lt;P&gt;Hi....I was trying to use a macro to loop through the list but I get an error message. Thanks.&lt;/P&gt;
&lt;PRE&gt;%macro Student();
Proc sql;
    Select distinct Date into :Dates separated by ' ' from have2;
Quit;

%do i=1 %to %sysfunc(countw(&amp;amp;Dates));
    %let Dates=%scan(&amp;amp;Dates,&amp;amp;i,%str( ));
data want;
    set have;
	by ID;
		if Start &amp;lt;= &amp;amp;Dates &amp;lt;= End then
    		Count + 1;
	output;
	run;

%end;
%mend;
%Student&lt;/PRE&gt;</description>
    <pubDate>Sun, 06 Jun 2021 21:22:58 GMT</pubDate>
    <dc:creator>twildone</dc:creator>
    <dc:date>2021-06-06T21:22:58Z</dc:date>
    <item>
      <title>re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746042#M233979</link>
      <description>&lt;P&gt;Hi...I have 2 datasets. The first has a Start and End Date for each ID. The second dataset has a list of dates. What I an trying to do is count the number of Dates listed in dataset have2 for each ID in dataset have that is between the Start and End dates.Any suggestions. Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input ID $ (Start End) (:yymmdd10.);
format Start End yymmdd10.;
cards;
1 20190519 20190601
2 20190306 20190324
3 20190822 20190830
;

data have2;
input Date :yymmdd10.;
format Date yymmdd10.;
cards;
20190522
20190528
20190615
20190820
20190823
20190827
;

data want;
input ID $ (Start End) (:yymmdd10.) NumberDays;
format Start End yymmdd10.;
cards;
1 20190519 20190601 2
2 20190306 20190324 0
3 20190822 20190830 2
;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Jun 2021 21:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746042#M233979</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-06-05T21:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746044#M233981</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have2 out=have2_t;
run;

data want;
    if _n_=1 then set have2_t;
    set have;
    array c col:;
    count=0;
    do i=1 to dim(c);
        if start&amp;lt;c(i)&amp;lt;end then count=count+1;
    end;
    keep start end id count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Jun 2021 21:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746044#M233981</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-05T21:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746046#M233983</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4061"&gt;@twildone&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi...I have 2 datasets. The first has a Start and End Date for each ID. The second dataset has a list of dates. What I an trying to do is count the number of Dates listed in dataset have2 for each ID in dataset have that is between the Start and End dates.Any suggestions. Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input ID $ (Start End) (:yymmdd10.);
format Start End yymmdd10.;
cards;
1 20190519 20190601
2 20190306 20190324
3 20190822 20190830
;

data have2;
input Date :yymmdd10.;
format Date yymmdd10.;
cards;
20190522
20190528
20190615
20190820
20190823
20190827
;

data want;
input ID $ (Start End) (:yymmdd10.) NumberDays;
format Start End yymmdd10.;
cards;
1 20190519 20190601 2
2 20190306 20190324 0
3 20190822 20190830 2
;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you are reading in these dates as SAS dates, they will be a number (the count of days since January 1, 1960), and you can just use a regular mathematical expression.&amp;nbsp; &amp;nbsp; I think you'll want two SET statements, one inside the other.&lt;/P&gt;
&lt;P&gt;The mathematical expression would be something fairly simple like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF Start &amp;lt;= Date &amp;lt;= End THEN
    Count + 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why don't you experiment with that code and two SET statements and see if you can get it working?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 21:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746046#M233983</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-05T21:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746063#M233995</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4061"&gt;@twildone&lt;/a&gt;&amp;nbsp;Here is an alternate solution with the help PROC SQL and Data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql noprint;
create table have_3 as
select a.*,b.date from have as a, have2 as b where date between start and end order by ID;
quit;

data have_4;
set have_3;
by Id;
if first.id then NumberDays=1;
else NumberDays+1;
if last.id;
drop date;
run;

proc sql;
create table want as 
select id,start,end,NumberDays from have_4
union all
select id,start,end ,0 as NumberDays from Have where id not in (select distinct(Id) from have_3)
order by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 05:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746063#M233995</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2021-06-06T05:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746068#M233999</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    a.id,
    a.start,
    a.end,
    count(b.date) as count
  from have a left join have2 b
  on a.start le b.date le a.end
  group by a.id, a.start, a.end;
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 07:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746068#M233999</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-06T07:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746124#M234025</link>
      <description>&lt;P&gt;Hi....I was trying to use a macro to loop through the list but I get an error message. Thanks.&lt;/P&gt;
&lt;PRE&gt;%macro Student();
Proc sql;
    Select distinct Date into :Dates separated by ' ' from have2;
Quit;

%do i=1 %to %sysfunc(countw(&amp;amp;Dates));
    %let Dates=%scan(&amp;amp;Dates,&amp;amp;i,%str( ));
data want;
    set have;
	by ID;
		if Start &amp;lt;= &amp;amp;Dates &amp;lt;= End then
    		Count + 1;
	output;
	run;

%end;
%mend;
%Student&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Jun 2021 21:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746124#M234025</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-06-06T21:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746134#M234026</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4061"&gt;@twildone&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi....I was trying to use a macro to loop through the list but I get an error message.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What error? Show us the LOG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why add in macro complications, when working solutions have been posted above?&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 22:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746134#M234026</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-06T22:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746136#M234027</link>
      <description>&lt;P&gt;That macro has got &lt;STRONG&gt;absolutely nothing&lt;/STRONG&gt; to do with my code. Try that as posted and look if it does the job.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 22:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746136#M234027</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-06T22:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746137#M234028</link>
      <description />
      <pubDate>Sun, 06 Jun 2021 22:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746137#M234028</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-06-06T22:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746142#M234031</link>
      <description>&lt;P&gt;Hi.....I have included the log below with the error message. Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;27         
28         GOPTIONS ACCESSIBLE;
29         data have;
30         input ID $ (Start End) (:yymmdd10.);
31         format Start End yymmdd10.;
32         cards;

NOTE: The data set WORK.HAVE has 3 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      
36         ;

37         
38         data have2;
39         input Date :yymmdd10.;
40         format Date yymmdd10.;
41         cards;

NOTE: The data set WORK.HAVE2 has 6 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      
48         ;

49         
50         %macro Student();
51         Proc sql;
52             Select distinct Date into :Dates separated by ' ' from have2;
2                                                          The SAS System                                 11:33 Sunday, June 6, 2021

53         Quit;
54         
55         %do i=1 %to %sysfunc(countw(&amp;amp;Dates));
56             %let Dates=%scan(&amp;amp;Dates,&amp;amp;i,%str( ));
57         data want;
58             set have;
59         	by ID;
60         		if Start le &amp;amp;Dates le End then
61         			Count+1;
62         	output;
63         	run;
64         
65         %end;
66         %mend;
67         %Student
68         
69         GOPTIONS NOACCESSIBLE;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds
      


NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 3 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

NOTE: Line generated by the invoked macro "STUDENT".
69          data want;     set have;  by ID;   if Start le &amp;amp;Dates le End then     Count+1;  output;  run;
                                                                     ___
                                                                     388
                                                                     76

ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 3 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: Line generated by the invoked macro "STUDENT".&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Jun 2021 23:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746142#M234031</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-06-06T23:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746143#M234032</link>
      <description>&lt;P&gt;Hi Kurt....I did try your suggestion and from the log below it looks like I ran out of disk space. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.
NOTE: The query requires remerging summary statistics back with the original data.
ERROR: Insufficient space in file WORK.'SASTMP-000007194'n.UTILITY.
ERROR: File WORK.'SASTMP-000007194'n.UTILITY is damaged. I/O processing did not complete.
NOTE: Error was encountered during utility-file processing. You may be able to execute the SQL statement successfully if you 
      allocate more space to the WORK library.
ERROR: There is not enough WORK disk space to store the results of an internal sorting phase.
ERROR: An error has occurred.

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
18848      quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           10:31.69
      cpu time            6:35.82
      
18849  &lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Jun 2021 23:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746143#M234032</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-06-06T23:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746144#M234033</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4061"&gt;@twildone&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi.....I have included the log below with the error message. Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;   
50         %macro Student();
51         Proc sql;
52             Select distinct Date into :Dates separated by ' ' from have2;
2                                                          The SAS System                                 11:33 Sunday, June 6, 2021

53         Quit;
54         
55         %do i=1 %to %sysfunc(countw(&amp;amp;Dates));
56             %let Dates=%scan(&amp;amp;Dates,&amp;amp;i,%str( ));
57         data want;
58             set have;
59         	by ID;
60         		if Start le &amp;amp;Dates le End then
61         			Count+1;
62         	output;
63         	run;
64         
65         %end;
66         %mend;
67         %Student
68         
69         GOPTIONS NOACCESSIBLE;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds
      


NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 3 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

NOTE: Line generated by the invoked macro "STUDENT".
69          data want;     set have;  by ID;   if Start le &amp;amp;Dates le End then     Count+1;  output;  run;
                                                                     ___
                                                                     388
                                                                     76

ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 3 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: Line generated by the invoked macro "STUDENT".&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you are trying to debug a macro, you need to place the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before the running of the macro, and then run it again. This writes a lot of useful information to the LOG, and shows you the actual SAS code the macro is generating. This will enable you to see if the macro is doing the right thing, or not. So I suggest you try it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I try this on your code, I see&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;MPRINT(STUDENT):   if Start le 2019-05-22 le End then Count+1;&lt;/PRE&gt;
&lt;P&gt;which doesn't do what you want. This line looks to see if the value 2019 minus 05 minus 22 (that's what it says) is between the values of START and END. Can you figure out how to change this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, later, more errors coming from this line:&lt;/P&gt;
&lt;PRE&gt; MPRINT(STUDENT):   if Start le le End then Count+1;&lt;/PRE&gt;
&lt;P&gt;Can you figure out how to change this to make it work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I said earlier, why introduce the complications of macros when working code has already been provided? (my code works on your data sets HAVE and HAVE2)&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 23:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746144#M234033</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-06T23:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746145#M234034</link>
      <description>&lt;PRE&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;/PRE&gt;
&lt;P&gt;I see in the first NOTE that a Cartesian product is occurring with the way your SQL is coded.&amp;nbsp; A Cartesian product basically involves joining every possible combination of rows between two tables -- which if the tables are large will require &lt;STRONG&gt;inordinate&lt;/STRONG&gt; amounts of disk space.&amp;nbsp; Really, I think this is an issue more with how the query is coded than it is about not enough WORK space.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 23:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746145#M234034</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-06T23:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746154#M234039</link>
      <description>&lt;P&gt;So, because of the size of the cartesian join, we need to forego the obvious SQL solution and use some data step trickery to do it in a sequential pass, by using an array indexed by dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ (Start End) (:yymmdd10.);
format Start End yymmdd10.;
cards;
1 20190519 20190601
2 20190306 20190324
3 20190822 20190830
;

data have2;
input Date :yymmdd10.;
format Date yymmdd10.;
cards;
20190522
20190528
20190615
20190820
20190823
20190827
;

%let array_start = %sysfunc(inputn(19000101,yymmdd8.));
%let array_end = %sysfunc(inputn(21001231,yymmdd8.));

data want;
set have;
if _n_ = 1
then do;
  array dates {&amp;amp;array_start.:&amp;amp;array_end.} _temporary_;
  do while (not done);
    set have2 end=done;
    dates{date} = 1;
  end;
end;
count = 0;
do _n_ = start to end;
  count = sum(count,dates{_n_});
end;
drop date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Jun 2021 08:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746154#M234039</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-07T08:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746172#M234043</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;the cartesian join was the result of me trying a brute force, simple approach first, and to show that no macro coding is needed at all.&lt;/P&gt;
&lt;P&gt;With the data prohibiting that, I then switched to a data step that will handle anything that can even be stored in the target environment.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 09:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746172#M234043</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-07T09:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746223#M234074</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ (Start End) (:yymmdd10.);
format Start End yymmdd10.;
cards;
1 20190519 20190601
2 20190306 20190324
3 20190822 20190830
;

data have2;
input Date :yymmdd10.;
format Date yymmdd10.;
cards;
20190522
20190528
20190615
20190820
20190823
20190827
;

data want;
 if _n_=1 then do;
  if 0 then set have2;
  declare hash h(dataset:'have2');
  h.definekey('date');
  h.definedone();
 end;
set have;
count=0;
do date=start to end;
  if h.check()=0 then count+1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Jun 2021 12:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746223#M234074</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-07T12:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746321#M234110</link>
      <description>&lt;P&gt;Hi Kurt....I tried your suggestion and I am getting and Out of Range Error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;50         %let array_start = %sysfunc(inputn(19000101,yymmdd8.));
51         %let array_end = %sysfunc(inputn(21001231,yymmdd8.));
52         
2                                                          The SAS System                                 12:27 Monday, June 7, 2021

53         data want;
54         set have;
55         if _n_ = 1
56         then do;
57           array dates {&amp;amp;array_start.:&amp;amp;array_end.} _temporary_;
58           do while (not done);
59             set have2 end=done;
60             dates{date} = 1;
61           end;
62         end;
63         count = 0;
64         do _n_ = start to end;
65           count = sum(count,dates{_n_});
66         end;
67         drop date;
68         run;

NOTE: Invalid numeric data, Dates='20000103' , at line 60 column 12.
ERROR: Array subscript out of range at line 60 column 5.
ID=104 Start=20010312 End=20010629&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Jun 2021 17:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746321#M234110</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-06-07T17:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746326#M234111</link>
      <description>&lt;P&gt;Hi Ksharp…..I tried your suggested code and I am getting the following error message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR 133-185: A loop variable cannot be an array name or a character variable; It must be a scalar numeric.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 17:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746326#M234111</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-06-07T17:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746335#M234113</link>
      <description>&lt;P&gt;The dates&amp;nbsp;&lt;STRONG&gt;must&lt;/STRONG&gt;, of course, be stored as SAS dates, as in your example have2 that I used to develop and test the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start with copy/pasting and submitting my code as is, and work from there.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 18:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746335#M234113</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-07T18:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: re: counting days between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746383#M234135</link>
      <description>&lt;P&gt;Hi Kurt......thanks for all your help...greatly appreciate and you were right the issue was the dates......thanks once again.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 01:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-counting-days-between-two-dates/m-p/746383#M234135</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-06-08T01:11:16Z</dc:date>
    </item>
  </channel>
</rss>

