BookmarkSubscribeRSS Feed
theflunkee
Fluorite | Level 6

I have two tables (a and b) where both tables have column "time" and the tables has different number of rows (b has more rows than a)

However, a.time and b.time are not the same and I hope to merge the two tables to a, using time as constraint.

I want data from b only be merge to a, where b.time is the closest time to a.time, but less than a.time.

Thinking how to use proc sql for the data.... my previous attempts reported an error for insufficient memory... Many Thanks

4 REPLIES 4
EyalGonen
Barite | Level 11

An approach with SQL could be to join tables by a.time >= b.time (or maybe by a.time between b.time and b.time - 1 week for example to limit the results) that would produce a 1:n join then you could group by a.time and select the rows HAVING b.time = max(b.time)

 

theflunkee
Fluorite | Level 6

I got the following error....
ERROR: Sort execution failure.

 

proc sql; create table a_vs_b
as select a.S1, b.S2
from tablea as a left join tables as b
on a.time >= b.time
group by a.time
having b.time=max(b.time);
quit;
andreas_lds
Jade | Level 19

Please post data in usable form and the expected result.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2117 views
  • 0 likes
  • 3 in conversation