As others have pointed out, you need to help us help you. A start would be to provide sample data, in the form of a working data step, a sample result you expect from that data, and the code you used to get those results. This will help answer a lot of questions, not the least of which is "what is a week (any seven days? Monday-Sunday?)".
And even in your own terms, please be careful in describing your algorithm. In particular you wrote:
The weekly return for the week ending 19890915 should then be calculated as (3 + 0.0416)/3.083 The 3 in the numerator is the price on 19890915. The 3 in the denominator is the price on prior week 19890908.
There is no "3 in the denominator". Presumably you meant 3.083 as the price on 19890915. You hope that we will be unambiguous and comprehensive in our responses. Please return the favor.
Now, as to the use of a macro - there may be no need to create macro code. You may very well be able to do what you want with data step programming, or possibly a particular PROC available in SAS (maybe PROC EXPAND, but it's too early to say). But we can provide no advice without being informed clearly about your data, your expected outcome, and your code.
You mention PERMNO, so I assume you are using CRSP daily stock price data. Probably your dataset is sorted by PERMNO/DATE. If so, you can quite possibly run a single data step to read in this data, create a series of weekly returns for each PERMNO and go on to your analysis work. CRSP data (at least the NYSE data) goes back to December 1925, so you may be dealing with enough data that programming efficiency becomes paramount.
BTW very often CRSP daily (that's daily in term of market-trading-days) already has daily return values, one including dividends, and one without. So you might choose to compound daily returns to get a weekly return, in contrast to the algorithm you suggested.. Given there are at most 5 daily returns per week (well there were actually 6 trading days/week early in the CRSP historical data) you would not suffer from precision issues that can arise from a long series of calculations.
BTW, once you've addressed the efficiency issue. you need to make sure you've addressed stock splits. But I recommend that issue should be deferred until you have a working program for large datasets.
We look forward to helping once we know what help is actually needed.
... View more