BookmarkSubscribeRSS Feed
Ibad
Calcite | Level 5

Hi, I have just started using SAS. I have a question, where I need to get answers in Years. I have got it in months by Month + 1; command. How can I get a column of years parallel to months, where I can have the year number for each corresponding month. E.g. month 25 falls into year 3.

6 REPLIES 6
Kurt_Bremser
Super User

Use the mod() function to detect the start of a new year:

year = 0;
do month = 1 to 36;
  if mod(month,12) = 1 then year + 1;
  /* further processing */
end;

All of this in a data step, of course.

Ibad
Calcite | Level 5
Thank you sir, the years are formed but I think i have written the code at some incorrect location, and the values of capital and interest are changed.

Can you help me where to place the above command?
Ibad
Calcite | Level 5

Thanks for your reply. I was able to create years, but in the process, the value of capital and interest also got fixed with the years. Maybe I have placed the code at a wrong place. Please, can you let me know the correct location? 

 

 This is what my initial code was: 

 

data file;
format Year Month Capital Interest;
Principal = 4000;
Deposits = 90;
do until (Principal >= 100000);
Interest = (Principal + Deposits) * 0.01;
Capital = Interest + Capital;
Month + 1;
output;
end;
run;

Ibad
Calcite | Level 5

Please help me in writing a DO loop code for variables that are fixed during a year, and change after the year-end. For example, variable changes from A to B and then to C at the end of 12 month period.