Hi,
Firstly, please don't post Office files, they are a danger and I for one would not download them. Post test in the form of a datastep in the post, help can be found here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712
Secondly, your code is next to impossible to read, no good programming practices followed there. Personally, I would think that doing this in Base SAS rather than SQL would make your code simpler and easier to read:
data want;
set have (where=sch_class in ('539','540','541','812','813') and upload_date >= '31DEC2015'd);
by sch_class tran_type;
retain shares_subscribed shares_redeemed;
if sch_class in ("SWIN","SWINC","UNSAL","UNSALC") then do;
shares_subscribed=sum(shares_subscribed,trade_units);
...
end;
if sch_class in ("SWOUT","SWOUT","UNPUR","UNPURC") then do;
shares_redeeemed=sum(shares_redeemed,trade_units);
...
end;
if last.tran_type then output;
run;
Note that most of your case statements there are of no additional value to the logic, you already restrict the data to the '539','540' etc, so why add that to the case each time?
... View more