Hi everyone, I found it's wired that my SQL left join output duplicates values, seems the Cartesian product was not cleaned/selected by SAS. My left join didn't result in the same number of rows as in my left table. I run a sort with nodupkep option and cleaned up the duplicates by hand, but I am very curious what happened. Here are the proc contents for my two table: Here are my SQL Left Join code: proc sql;
create table MergedHDF as
select coalesce(p.ProductYear,q.ProductYear)as ProductYear,
p.MeasurementYear,
coalesce(p.SubmissionId, q.SubmissionId)as SubmissionId,
coalesce(p.OrganizationId,q.OrganizationId)as OrganizationId,
coalesce(p.OrganizationName,q.OrganizationName) as OrganizationName,
coalesce(p.ProductLine, q.ProductLine) as ProductLine,
coalesce(p.ReportingProduct, q.ReportingProduct) as ReportingProduct,
coalesce(p.MeasureCode,q.MeasureCode) as MeasureCode,
p.MeasureName, p.IndicatorName, p.IndicatorCode,
p.Rate, p.Numerator, p.Denominator, p.EligiblePopulation,
p.Type, p.Region, p.sum_num, p.sum_denom,p.AggregateRate,
coalesce(p.Status,q.Status) as Status,q.states
from averagedrate as p
left join
combinedstates as q
on p.organizationid=q.organizationid and p.SubmissionId=q.submissionId and
p.ProductLine=q.ProductLine and p.ReportingProduct=q.ReportingProduct;
quit;
proc sort data=mergedHDF nodupkey;
by measurecode productyear organizationid submissionid productline reportingproduct status;
run; Here are my Log: Note that there are 5426 rows, rather than 2816 rows as in my left table. Here are the log after I remove duplicates: This really confuses me, any idea on why this happened will be greatly appreciated!
... View more