I know this is a stale thread, but it was on my "recommended by SAS" box, so I took a look. Here's a solution:
data want;
merge A (rename=(date=adate))
B ;
by id ;
if first.id then cumsum=0;
if adate-365 <= date <=adate then cumsum+newsnumber;
if last.id;
run;
Notes:
This program assumes that dataset B is sorted by ID/date, and dataset A is sorted by ID.
It also assumes that A never has more than 1 record per ID.
The program assumes that the user want one record per id, even when cumsum=0.
If you want to account for leap years, then the "if adate-365 <= date ..." statement should be changed to:
if intnx('year',adate,-1,'s') <=date <=adate then cumsum+newsnumber;
The "trick" here is to merge by id, NOT by id date. This results in the dataset A record merged with all the dataset B records for the same id, even though the date in A does not precede all the dates in B. Of course you have to rename date in A, so as to not collide with date values from B. If there is no obs in A for a given id, then adate=.
... View more