New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
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. 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 3503 views
  • 0 likes
  • 2 in conversation