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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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