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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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