Hi Kurt....I tried your suggestion and I am getting and Out of Range Error message.
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 {&array_start.:&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
The dates must, of course, be stored as SAS dates, as in your example have2 that I used to develop and test the code.
Start with copy/pasting and submitting my code as is, and work from there.
Hi Kurt......thanks for all your help...greatly appreciate and you were right the issue was the dates......thanks once again.
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;
Hi Ksharp…..I tried your suggested code and I am getting the following error message:
ERROR 133-185: A loop variable cannot be an array name or a character variable; It must be a scalar numeric.
It is weird that I got nothing in log.
or Try this one :
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 i=start to end;
if h.check(key:i)=0 then count+1;
end;
drop i date;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.