BookmarkSubscribeRSS Feed
FriedEgg
SAS Employee

Use double set with key lookup to account for missing dates, similar to my previous method using double set statements and point:

data foo(index=(date /nomiss /unique));
call streaminit(12345);
do date='01JAN1960'd to today();
  count=int(rand('uniform')*10e2);
  if rand('table',.95)=1 then output;
end;
format date date9.;
run;

data bar;
set foo(rename=(date=_date)) nobs=nobs;
sum=.;
miss=0;
do date=_date-10 by 1 while ( date < _date and _n_ > 10 /* and miss=0 */ );
  set foo key=date/unique;
  if _iorc_ then do;
   _iorc_=0;
   _error_=0;
   miss+1;
  end;
  else do;
   sum+count;
  end;
end;

*if miss>1 then call missing(sum);
date=_date;
drop _date;
run;

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 5131 views
  • 2 likes
  • 10 in conversation