BookmarkSubscribeRSS Feed
Akarsh91
Calcite | Level 5

Dear experts, 

 

I have the following data: 

 

data have;
  infile datalines dlm=',' dsd truncover;
  input ID Date:anydtdte. Returns Delisting_return month newmonth year;
  format date date9.;
  datalines;
1,1968-01-28,1.01,,1,10,1968
1,1968-02-28,1.04,,2,11,1968
1,1968-03-28,1.001,,3,12,1968
1,1968-04-28,1.005,,4,01,1968
1,1968-05-28,1.02,,5,02,1968
1,1968-06-28,1.02,,6,03,1968
1,1968-07-28,1.06,,7,04,1968
1,1968-08-28,1.06,,8,05,1968
1,1968-09-28,1.0014,1.0014,9,06,1968;
run; 

ID    Date                Returns      Delisting return        month   newmonth      year

 

1    1968-01-28      1.01                                             1               10                1968

1    1968-02-28    1.04                                              2                11                  1968

1    1968-03-28     1.001                                           3                12                 1968

1   1968 -04-28     1.005   .                                       4                1                  1968

1   1968-05-28     1.02                                              5                 2                 1968

1   1968-06-28      1.02                                             6                 3              1968

1    1968-07-28     1.06                                              7                4               1968

1    1968-08-28      1.06                                             8                 5           1968

1   1968-09-28       1.0014                    1.0014          9                 6            1968

 

I would like to calculate rolling returns. The example above is just a sample. My original dataset however has more that 500000 observations. I would like to do the following: 

 

My portfolio in this case has only one stock. So ID = 1. I want to calculate the return of this stock for 2 months after I buy it on a rolling basis. For example if I bought it on 1968-01-28 then I want to calulate the return up to 1968-03-28. If I buy it on 1968-02-28 then I want to calculate the return until 1968-04-28. And so on until the last available formation period. 

 

I would later like to implement the same methodology on the large dataset with many stocks and larger formation periods. 

 

Could you please help me with an appropriate code or procedure for this task? If you need any more information please write. Thank you in advance. 

 

Regards

Akarsh91

1 REPLY 1

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1645 views
  • 0 likes
  • 2 in conversation