permno, portweight 10001, 0.2 10006, 0.3 10010, -0.4
We want to calculate the returns to this portfolio over January 2001.
So we say:
data msf; set crsp.msf(keep=permno date ret); where intnx('month', date, 1)-1 = '31Jan2001'd); *Moves date to end-of-month; run;
and then merge this with PORTWEIGHTS by PERMNO to get a dataset PORTWEIGHTSRETS, and then just say
proc means data=portweightsrets; var ret/weight=portweight; run;
The problem is that SAS sets negative weights to zero when it calculates means. So permno 10010, for instance, will not be included in the portfolio.
The straightforward way to handle this is to say:
data portweights; set portweights; modifiedret=ret; if portweight<0 then modifiedret=-ret; absportweight=abs(portweight); run; proc means data=portweightsrets; var modifiedret/weight=absportweight; run;