It's impossible to reply without sample data, but one thing stands out:
> I format the date of both dataset as yyq. (ie. year and quarter), then sort them
formatting has no effect on the sort or the merge, it only affects how the value is displayed.
If you want to merge by quarter you need to make this known. Either create a new variable, or change the SQL:
on dataset1.PERMNO=dataset2.LPERMNO
and put(dataset1.DATE,yyq.)=put(dataset2.DATADATE,yyq.);
... View more