As ballardw points out, if you have multiple rows for acct (e.g. multiple dates per acct) then you may get mutiple rows for a given acct in your output depending on how your structure your query. The following sample assumes only one row per acct in each dataset, and that all accts exist in both datasets. /* creates a dataset with one record for each 'acct' with a random date (dateA) */ DATA a; drop i datedif; format dateA date9.; datedif = today() - '01Jan1960'd + 1; do i = 1 to 100 ; acct + 1 ; dateA = round((datedif*ranuni(0)))+1 ; output; end; run; /* creates a second dataset, one record for each 'acct' with another random date (dateB) */ DATA b; drop i datedif; format dateB date9.; datedif = today() - '01Jan1960'd + 1; do i = 1 to 100 ; acct + 1 ; dateB = round((datedif*ranuni(0)))+1 ; output; end; run; /* create table of matches where dateA is less than dateB+365) */ proc sql; create table want as select a.acct, a.dateA, b.dateB, intnx('year', dateb, 1, 'same') as cutoffdt format=date9. from a, b where a.acct=b.acct and a.datea<intnx('year', dateb, 1, 'same') ; quit;
... View more