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. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 3779 views
  • 0 likes
  • 2 in conversation