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.
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.
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;
You have created an infinite loop since the value of principal never changes.
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.
I merged the threads because the question is basically the same.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.