Think about it this way
0 is 01JAN1960
1 is 02JAN1960
2 is 03JAN1960
...
365 is 31DEC1960
366 is 01JAN1961
or a simple program will clear this up
data a;
do dt=0 to 368 by 1;
dt1=dt;
output;
end;
format dt1 $date9.;
run;
Think about it this way
0 is 01JAN1960
1 is 02JAN1960
2 is 03JAN1960
...
365 is 31DEC1960
366 is 01JAN1961
or a simple program will clear this up
data a;
do dt=0 to 368 by 1;
dt1=dt;
output;
end;
format dt1 $date9.;
run;
why we are adding 366 count extra date for 01jan1961 is it condition to add for every year start with first day?
I repeat: SAS dates are counts of days, and since 1960 was a leap year with 366 days, and the count starts at the beginning of 1960, 1961-01-01 will be day #366.
@Bhagyalakshmi wrote:
why we are adding 366 count extra date for 01jan1961 is it condition to add for every year start with first day?
Not sure what you are asking. But the better way to think about is that SAS is just counting days (not years). Some years have 365 days and others (leap years) have 366 days 1960 happens to be one that has 366 days. The first day of 1960 is stored as 0. Hence the first day of 1961 is 366 days later which is 366. The first day of 1962 is 365 days later which is the number 731. Dates before 1/1/1960 will be stored as negative numbers. Since 1959 had 365 days the first day of 1959 is the number -365.
Let's check how many days the years from 1958 to 1962 have.
data test;
do year=1958 to 1963 ;
date=mdy(1,1,year);
number=date;
days_last_year=dif(date);
output;
end;
format date date9.;
run;
SAS dates are counts of days, with 1960-01-01 being day zero. Since 1960 was a leap year, 1961-01-01 is day 366.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.