I have a task in SAS; What I need to do is to assign the October Current_value (60) in the column Fake_1 and let repeat it only for the months of October, November and December; the same logic should be applied to valorise column Fake_2, and assign the Current_Value of November both for November and December of columns Fake_2. That's how my table should look like:
Product_Code Division Category Payment_Frequency Selling_Type expiring_month Current_Value Fake_1 Fake2
C611720 17822 AZ Monthly NSD 1 63
C611720 17822 AZ Monthly NSD 2 72
C611720 17822 AZ Monthly NSD 3 23
C611720 17822 AZ Monthly NSD 4 24
C611720 17822 AZ Monthly NSD 5 90
C611720 17822 AZ Monthly NSD 6 87
C611720 17822 AZ Monthly NSD 7 56
C611720 17822 AZ Monthly NSD 8 43
C611720 17822 AZ Monthly NSD 9 57
C611720 17822 AZ Monthly NSD 10 60 60
C611720 17822 AZ Monthly NSD 11 48 60 48
C611720 17822 AZ Monthly NSD 12 32 60 48
How can it be done? I think the solution would be using retain function, but I am struggling a bit as when I use it, sas prints me value of 48 and 32 for Nov/Dec values in the column fake1.
data sox_8;
set sox_7;
retain Fake_1;
if Expiring_Month > 9 then Fake_1 = Current_Value;
run;
Thank you for the support
The
> 9
means it updates for 10, 11, and 12. You want only to update on 10, so:Now, you may want to extend your code like so:
This will update for both 10 and 11. Presumably you'll eventually have code that, for 2021 perhaps, would need to do this for more than two months - this allows you the beginning of a program that will automatically pick up what it needs (you'll want to also calculate
Fake
dimensions based on the month you run, probably with a macro variable).Of course, please don't use
Fake
as a variable name in your real code!