Help using Base SAS procedures

is there a way to calculate number of days in a month

Reply
Occasional Contributor
Posts: 12

is there a way to calculate number of days in a month

Hi ,

I am a newbee to this community ,.. but i follow the question and answers posted here.

My question is there a way that we can calculate days in a given month EX: Jan =31 days Feb = 28 or 29.

Moreover i need to check given year is leap year or normail year then need to calculate number of days in each month.

Any help appreciated!!

Super Contributor
Posts: 1,636

is there a way to calculate number of days in a month

Hi,

You can use the code below to calculate the number of day in 2011:

data want;

do month=1 to 11;

days=mdy(month+1,1,2011)-mdy(month,1,2011);

output;

end;

month=12;

days=mdy(1,1,2012)-mdy(12,1,2011);

output;

proc print;run;

                                        Obs    month    days

                                         1       1      31

                                         2       2      28

                                         3       3      31

                                         4       4      30

                                         5       5      31

                                         6       6      30

                                         7       7      31

                                         8       8      31

                                         9       9      30

                                        10      10      31

                                        11      11      30

                                        12      12      31

Linlin

Regular Contributor
Posts: 171

Re: is there a way to calculate number of days in a month

data dates;

input month $;

start = input(month, anydtdte.);

num_days = day(intnx('MONTH', start, 0, 'END'));

put (month num_days) (=);

datalines;

Jan11

Apr11

Feb11

Feb12

;

run;

Ask a Question
Discussion stats
  • 2 replies
  • 159 views
  • 6 likes
  • 3 in conversation