BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Bhagyalakshmi
Fluorite | Level 6
I have one doubt about why in that point of 01Jan1960 is 0 then next year that is 366 I can't understand it well
Anyone pls clear my doubt !!!
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
Bhagyalakshmi
Fluorite | Level 6

why we are adding 366 count extra date for 01jan1961 is it condition to add for every year start with first day?

Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

@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;

Tom_0-1719584446746.png

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1100 views
  • 6 likes
  • 4 in conversation