Write and run SAS programs in your web browser

Calculation Query/Opposite to Lag?

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

Calculation Query/Opposite to Lag?

[ Edited ]

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.

 

 

 

DATEMONTHF1F2?????
01-Oct-15110.24015.48.18418905
01-Oct-1522.02054420.690684.705416607
01-Oct-1531.2427582.5110472.328786667
01-Oct-1541.2558261.5606871.873886563
01-Oct-1550.9374241.1772421.492154466
01-Oct-1561.2117131.1358891.591760354
01-Oct-1571.3136451.591761.31364454
01-Oct-158111
01-Nov-15110.2401510.2401536.67977719
01-Nov-1522.02054420.690683.581955744
01-Nov-1531.2427582.5110471.772767743
01-Nov-1541.2558261.5606871.426479162
01-Nov-1550.9374241.1772421.135889063
01-Nov-1561.2117131.1358891.211713143
01-Nov-157111

Accepted Solutions
Solution
‎06-23-2016 03:11 AM
Grand Advisor
Posts: 9,335

Re: Calculation Query/Opposite to Lag?

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;

View solution in original post


All Replies
Solution
‎06-23-2016 03:11 AM
Grand Advisor
Posts: 9,335

Re: Calculation Query/Opposite to Lag?

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;
Contributor
Posts: 57

Re: Calculation Query/Opposite to Lag?

Thanks for your help this worked Smiley Happy

Post a Question
Discussion Stats
  • 2 replies
  • 132 views
  • 0 likes
  • 2 in conversation