Hi there
I have the below dataset as my input.
What I am trying to do is calcualte column ?????
The calculation needs to start at month 8 for Oct 2015 for instance.
This will always be 1.
1.31364454 is the result of the 1 under column ????? multiplied by month 7 1.313645
1.591760354 is the result of the 1.31364454 under ????? muliplied by month 6 1.211713
Is there any code that will allow me to achieve this?
I have tried using the retain fucntion but I am going down the wrong route possibly here.
| DATE | MONTH | F1 | F2 | ????? |
| 01-Oct-15 | 1 | 10.24015 | . | 48.18418905 |
| 01-Oct-15 | 2 | 2.020544 | 20.69068 | 4.705416607 |
| 01-Oct-15 | 3 | 1.242758 | 2.511047 | 2.328786667 |
| 01-Oct-15 | 4 | 1.255826 | 1.560687 | 1.873886563 |
| 01-Oct-15 | 5 | 0.937424 | 1.177242 | 1.492154466 |
| 01-Oct-15 | 6 | 1.211713 | 1.135889 | 1.591760354 |
| 01-Oct-15 | 7 | 1.313645 | 1.59176 | 1.31364454 |
| 01-Oct-15 | 8 | 1 | 1 | 1 |
| 01-Nov-15 | 1 | 10.24015 | 10.24015 | 36.67977719 |
| 01-Nov-15 | 2 | 2.020544 | 20.69068 | 3.581955744 |
| 01-Nov-15 | 3 | 1.242758 | 2.511047 | 1.772767743 |
| 01-Nov-15 | 4 | 1.255826 | 1.560687 | 1.426479162 |
| 01-Nov-15 | 5 | 0.937424 | 1.177242 | 1.135889063 |
| 01-Nov-15 | 6 | 1.211713 | 1.135889 | 1.211713143 |
| 01-Nov-15 | 7 | 1 | 1 | 1 |
data have;
infile cards expandtabs;
input DATE : date11. MONTH F1 F2;
format DATE date11.;
cards;
01-Oct-15 1 10.24015 . 48.18418905
01-Oct-15 2 2.020544 20.69068 4.705416607
01-Oct-15 3 1.242758 2.511047 2.328786667
01-Oct-15 4 1.255826 1.560687 1.873886563
01-Oct-15 5 0.937424 1.177242 1.492154466
01-Oct-15 6 1.211713 1.135889 1.591760354
01-Oct-15 7 1.313645 1.59176 1.31364454
01-Oct-15 8 1 1 1
01-Nov-15 1 10.24015 10.24015 36.67977719
01-Nov-15 2 2.020544 20.69068 3.581955744
01-Nov-15 3 1.242758 2.511047 1.772767743
01-Nov-15 4 1.255826 1.560687 1.426479162
01-Nov-15 5 0.937424 1.177242 1.135889063
01-Nov-15 6 1.211713 1.135889 1.211713143
01-Nov-15 7 1 1
;
run;
proc sort data=have(where=(month le 8)) out=temp;
by date descending month;
run;
data want;
set temp;
by date;
retain xxxx;
if first.date then xxxx=1;
xxxx=xxxx*F1;
run;
proc sort data=want;by date month;run;
data have;
infile cards expandtabs;
input DATE : date11. MONTH F1 F2;
format DATE date11.;
cards;
01-Oct-15 1 10.24015 . 48.18418905
01-Oct-15 2 2.020544 20.69068 4.705416607
01-Oct-15 3 1.242758 2.511047 2.328786667
01-Oct-15 4 1.255826 1.560687 1.873886563
01-Oct-15 5 0.937424 1.177242 1.492154466
01-Oct-15 6 1.211713 1.135889 1.591760354
01-Oct-15 7 1.313645 1.59176 1.31364454
01-Oct-15 8 1 1 1
01-Nov-15 1 10.24015 10.24015 36.67977719
01-Nov-15 2 2.020544 20.69068 3.581955744
01-Nov-15 3 1.242758 2.511047 1.772767743
01-Nov-15 4 1.255826 1.560687 1.426479162
01-Nov-15 5 0.937424 1.177242 1.135889063
01-Nov-15 6 1.211713 1.135889 1.211713143
01-Nov-15 7 1 1
;
run;
proc sort data=have(where=(month le 8)) out=temp;
by date descending month;
run;
data want;
set temp;
by date;
retain xxxx;
if first.date then xxxx=1;
xxxx=xxxx*F1;
run;
proc sort data=want;by date month;run;
Thanks for your help this worked 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.