- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you help me where to place the above command?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You have created an infinite loop since the value of principal never changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I merged the threads because the question is basically the same.