Help using Base SAS procedures

Merging monthly stock data with daily factor data

Reply
New Contributor
Posts: 2

Merging monthly stock data with daily factor data

Dear all,

I have monthly stock observations sorted according to the unique ID number for all US stocks and I need to merge the data file with the corresponding Fama French factors (having daily observations).

How can I achieve that in the new dataset to each monthly observation there is a factor observations matched?

The data looks like this:

Fama French:

date            SML     HML

19910102      a          d         

19910103      b          f

19910104      c          h

...

19910201       x          z

Stocks:

permno      date               price

1001         19910102          1

1001         19910201          2

1002         19910102          3

...

Merged:

permno     date          price     SML     HML    

1001         19910102     1          a          d

1001         19910201     2          x          z

1002         19910102     3          a          d

Thanks in advance Smiley Happy

Trusted Advisor
Posts: 1,128

Re: Merging monthly stock data with daily factor data

data data1;

    input date  SML$     HML$;

cards;

19910102      a          d        

19910103      b          f

19910104      c          h

;

data data2;

    input permno      date               price;

cards;

1001         19910102          1

1001         19910201          2

1002         19910102          3

;

proc sort data=data1;

    by date;

run;

proc sort data=data2;

    by date;

run;

data data3;

    merge data1(in=a) data2(in=b);

    by date;

    if b;

run;

thanks,

jagadish

Thanks,
Jag
New Contributor
Posts: 2

Re: Merging monthly stock data with daily factor data

Thank you so much, Jagadish!

Ask a Question
Discussion stats
  • 2 replies
  • 311 views
  • 3 likes
  • 2 in conversation