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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register 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
  • 3216 views
  • 2 likes
  • 10 in conversation