BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
parmis
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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;
--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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;
        
--
Paige Miller
parmis
Fluorite | Level 6

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 ....

PaigeMiller
Diamond | Level 26

@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;
--
Paige Miller
parmis
Fluorite | Level 6

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.

PaigeMiller
Diamond | Level 26

My code calls the variable MONTH and not DATE, which apparently is what you call the variable. You'd have to make that change.

--
Paige Miller
andreas_lds
Jade | Level 19
And if your date variable is not a sas-date, fix that issue before you do anything else with the data.
jfaruqui
Obsidian | Level 7

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;
Screen Shot 2019-03-07 at 3.09.09 AM.png

sas-innovate-white.png

Register Today!

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.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1887 views
  • 4 likes
  • 4 in conversation