🙂 Long time no see.
I have not enter this forum for a long time (a couple of weeks) .
Cartesian Product would be useful, but To the large dataset ,It will waste lots of time.
[pre]
data table1;
input week term;
datalines;
1 1
1 2
1 3
1 5
1 8
2 8
2 5
2 3
2 1
2 2
;
data table2;
input week term score;
datalines;
1 1 5
1 2 9
1 3 7
1 4 6
1 7 3
2 2 4
2 4 7
2 5 3
2 1 2
2 9 6
;
proc sql feedback;
select table1.week,table1.term,max(table2.score) as score
from table1,table2
where table2.week eq table1.week and table2.term between (table1.term - 1) and (table1.term + 1)
group by table1.week,table1.term;
quit;
[/pre]
or use left join just as patrick mentioned which can save your resource.
[pre]
proc sql feedback;
select table1.week,table1.term,max(table2.score) as score
from table1 left join table2
on table1.week eq table2.week
where table2.term between (table1.term - 1) and (table1.term + 1)
group by table1.week,table1.term;
quit;
[/pre]
I have to work now.Hope my code is right. 😉
and I test it ,it does work.
I really hope to spend enough time on this forum. But......
Ksharp
Message was edited by: Ksharp