My apologies for missing the tables. The first code creates the raw data set and the second one is the outcomes I intend. Here I attach the log. The first code. 1 data RAW;
2 format FIRM $8. DATE yymmddn8.;
3 do FIRM="GOOGL","MSFT";
4 do DATE="12apr2019"d to "22apr2019"d;
5 RETURN=round(0.01+sqrt(0.01)*rannor(1),0.01);
6 output;
7 end;
8 end;
9 run;
NOTE: The data set WORK.RAW has 22 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds The second code. 12 data PROCESSED;
13 set RAW;
14 by FIRM DATE;
15
16 /*1. Conventional. Works nicely, but too many lines*/
17 if first.FIRM then LOG=log(1+RETURN);
18 else LOG+log(1+RETURN);
19 CUMULATIVE=exp(LOG)-1;
20
21 /*2. Tried IFN to shorten, but doesn't work*/
22 LOG1=ifn(first.FIRM,log(1+RETURN),LOG1+log(1+RETURN));
23
24 /*3. Wondered if it's about LAG, but wasn't*/
25 LOG2=ifn(first.FIRM,log(1+RETURN),lag(LOG2)+log(1+RETURN));
26
27 /*4. Tried to accumulate by multiplying, but doesn't work*/
28 if first.FIRM then CUMULATIVE1=RETURN;
29 else CUMULATIVE1=(1+CUMULATIVE1)*(1+RETURN)-1;
30
31 /*5. Wondered if it's about LAG, but wasn't*/
32 if first.FIRM then CUMULATIVE2=RETURN;
33 else CUMULATIVE2=(1+lag(CUMULATIVE2))*(1+RETURN)-1;
34
35 /*6. Tried to shorten using IFN, but doesn't work*/
36 CUMULATIVE3=ifn(first.FIRM,RETURN,(1+CUMULATIVE3)*(1+RETURN)-1);
37
38 /*7. Tried the same thing with a LAG function, but doesn't work*/
39 CUMULATIVE4=ifn(first.FIRM,RETURN,(1+lag(CUMULATIVE4))*(1+RETURN)-1);
40 run;
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
22 at 22:39 22 at 25:44 20 at 29:20 20 at 33:20 22 at 36:37 22 at 36:50 22 at 36:61 22 at 39:37
22 at 39:55 22 at 39:66
NOTE: There were 22 observations read from the data set WORK.RAW.
NOTE: The data set WORK.PROCESSED has 22 observations and 11 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds Sorry again.
... View more