Hello,
I have a data set that contains a date filed (Jan 2019 ) and X(which is a number). I'd like to increase the X filed by 1.2% each month for the next 12 months.
for example if the value for Jan 2019 is 120, for February it will be 121.4 (120*(1+1.2)), but then I'd like to increase the new number by 1.2% for the next month and repeat the process for 12 months.
I appreciate your help.
@parmis wrote:
Thanks for your response. Is there a way to add the new data vertically like the following?
Date X
jan2019 100
Feb2019 110
March2019 120 ....
Well, not with ARRAYS, which aren't needed here.
data want;
set have;
output;
do i=2 to 12;
x=x*1.012;
month = intnx('month',month,1,'b');
output;
end;
format month monyy7.;
run;
Assumes your DATE variable contains actual numeric SAS date values.
data want;
set have;
array xs x1-x12;
array months month1-month12;
x1=x;
month1=date;
do i=2 to dim(xs);
xs(i)=xs(i-1)*1.012;
months(i) = intnx('month',months(i-1),1,'b');
end;
drop i;
format month: monyy7.;
run;
Thanks for your response. Is there a way to add the new data vertically like the following?
Date X
jan2019 100
Feb2019 110
March2019 120 ....
@parmis wrote:
Thanks for your response. Is there a way to add the new data vertically like the following?
Date X
jan2019 100
Feb2019 110
March2019 120 ....
Well, not with ARRAYS, which aren't needed here.
data want;
set have;
output;
do i=2 to 12;
x=x*1.012;
month = intnx('month',month,1,'b');
output;
end;
format month monyy7.;
run;
Thank you very much, this is exactly what I wanted but the dates are not changing. I have the first row of data(Jan2019) for all 12 months.
My code calls the variable MONTH and not DATE, which apparently is what you call the variable. You'd have to make that change.
I didn't quite get a clear sense of what you wanted your output to look like but maybe this might be the code you are looking for:
/* CREATING THE DUMMY DATA */
data have;
input date :monyy7. x @@;
format date MONYY7.;
CARDS;
JAN1990 345 MAR2009 980 NOV1973 290 FEB2011 330
;
run;
data want;
set have;
array m(*) AfterMonth1-AfterMonth12;
AfterMonth1=x * 1.012;
do i = 2 to 12;drop i;
m(i)=round((m(i-1) * 1.012),.01);
end;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.