- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data noofdays;
do i=1 to 12;
st='01jan2010'd ;
ed='01dec2010'd;
eom=intnx('month',st,ed,'e');
numdays=day(eom);
output;
end;
format st ed eom:date9.;
run;
count each month number of days in do loop
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just use the DAY() function to find the day of month of the last day of the month.
data noofdays;
do year=2010 to 2010;
do month=1 to 12 ;
eom=intnx('month',mdy(month,1,year),0,'end');
numdays=day(eom);
output;
end;
end;
format eom date9.;
run;
Obs year month eom numdays 1 2010 1 31JAN2010 31 2 2010 2 28FEB2010 28 3 2010 3 31MAR2010 31 4 2010 4 30APR2010 30 5 2010 5 31MAY2010 31 6 2010 6 30JUN2010 30 7 2010 7 31JUL2010 31 8 2010 8 31AUG2010 31 9 2010 9 30SEP2010 30 10 2010 10 31OCT2010 31 11 2010 11 30NOV2010 30 12 2010 12 31DEC2010 31
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What is your question?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You repeat the identical calculation 12 times. You may want to use i somewhere in that calculation 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As mentioned in the previous posts, if you're using a loop, you need to include that in your INTNX() call.
Since iteration value is represented by `i`, you need to include that in the third argument.
data noofdays;
do i=1 to 12;
st='01jan2010'd ;
ed='01dec2010'd;
/* Putting the `i` in the third argument */
eom=intnx('month',st,i,'e');
numdays=day(eom);
output;
end;
format st ed eom:date9.;
run;
This will increment the loop each time by the iteration value specified for a specified interval.
Looking at your original output, you will see that you get dates that are far away in the future. This is because your third argument is a SAS date which is internally represented as a number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Mag
Thank you very much for solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
MDY : create a SAS date from year, month and day; INTNX : count the number of date intervals between SAS dates; INTNX : find a SAS date a given number of intervals from a given date. Combine those to your purpose :
data nbOfDays;
year = 2010;
do month = 1 to 12;
numdays = 1 + intck("DAY", mdy(month, 1, year), intnx("MONTH", mdy(month, 1, year), 0, "END"));
output;
end;
run;
proc print data=nbOfDays; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi PGstats,
Thank you very much for solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just use the DAY() function to find the day of month of the last day of the month.
data noofdays;
do year=2010 to 2010;
do month=1 to 12 ;
eom=intnx('month',mdy(month,1,year),0,'end');
numdays=day(eom);
output;
end;
end;
format eom date9.;
run;
Obs year month eom numdays 1 2010 1 31JAN2010 31 2 2010 2 28FEB2010 28 3 2010 3 31MAR2010 31 4 2010 4 30APR2010 30 5 2010 5 31MAY2010 31 6 2010 6 30JUN2010 30 7 2010 7 31JUL2010 31 8 2010 8 31AUG2010 31 9 2010 9 30SEP2010 30 10 2010 10 31OCT2010 31 11 2010 11 30NOV2010 30 12 2010 12 31DEC2010 31