🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Lapis Lazuli | Level 10

## how to convert date into days

Hello everyone,

I have birthdate in  mm/dd/yyyy format. How can I calculate or convert it into days ?

For eg, birthdate is 04/16/1997. I want integer values of that date.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Meteorite | Level 14

## Re: how to convert date into days

Integer_Value = INPUT(Character_Value, MMDDYY10.);

Example:

``````Data	_NULL_;
Character_Value	=	PUT(TODAY(), MMDDYYS10.);
Integer_Value   =  INPUT(Character_Value, MMDDYY10.);
PUTLOG	"NOTE:  "  Character_Value=  Integer_Value=;
RUN;``````

Results:

`NOTE:  Character_Value=08/04/2021 Integer_Value=22496`

Be aware that the integer is a count of days since January 1st, 1960.  January 1st, 1960 is 0; January 2nd, 1960 is 1; January 3rd, 1960 is 2, etc.

Jim

8 REPLIES 8
Meteorite | Level 14

## Re: how to convert date into days

Integer_Value = INPUT(Character_Value, MMDDYY10.);

Example:

``````Data	_NULL_;
Character_Value	=	PUT(TODAY(), MMDDYYS10.);
Integer_Value   =  INPUT(Character_Value, MMDDYY10.);
PUTLOG	"NOTE:  "  Character_Value=  Integer_Value=;
RUN;``````

Results:

`NOTE:  Character_Value=08/04/2021 Integer_Value=22496`

Be aware that the integer is a count of days since January 1st, 1960.  January 1st, 1960 is 0; January 2nd, 1960 is 1; January 3rd, 1960 is 2, etc.

Jim

Super User

## Re: how to convert date into days

And just what "integer value" do you expect for that date?

Super User

## Re: how to convert date into days

A date in SAS is an integer (count of days from 1960-01-01). Do you need to calculate an offset from another date?

Meteorite | Level 14

## Re: how to convert date into days

@Kurt_Bremser wrote:

A date in SAS is an integer (count of days from 1960-01-01). Do you need to calculate an offset from another date?

Yes, @RAVI2000, if you have a SAS date, you already have an integer, an integer that represents a count of the number of days since January 1, 1960.  The question is:  Is this the integer that you want?

Some software (e.g. Excel) considers January 1, 1900 as Day 0.  SAS considers January 1, 1960 as Day 0.  Some may wish to count starting with January 1 of the year 1 A.D. as Day 0.  What do you want your integer value to represent?

Jim

Lapis Lazuli | Level 10

## Re: how to convert date into days

Yes, I need the Integer.
Meteorite | Level 14

## Re: how to convert date into days

@RAVI2000 wrote:
Yes, I need the Integer.

OK, great.  Did my earlier reply help you to get that integer?  And what do you want that integer to represent?

Jim

Super User

## Re: how to convert date into days

@RAVI2000 wrote:
Yes, I need the Integer.

Per definition, there is an infinite number of integers.

And even with the limitations of SAS, this still means 2 to the power of 54.

So you need to be much more specific and tell us which integer you need.

Super User

## Re: how to convert date into days

@RAVI2000 wrote:

Hello everyone,

I have birthdate in  mm/dd/yyyy format. How can I calculate or convert it into days ?

For eg, birthdate is 04/16/1997. I want integer values of that date.

Thanks

Note that SAS variables are not IN any format. The value is stored as either a fixed length character string or a floating point number.  A format is instructions on how to display the values as text.  A variable can have a format permanently attached to override the default way that SAS would normally display the value.

So if you have a numeric variable BIRTHDATE with the MMDDYY10. format attached to it then you already have BIRTHDATE as an integer.  If you want SAS to display it as an integer just remove the format.

``format birthdate;``

Or attach a different format:

``format bithdate comma7.;``

If you have a character variable BIRTHDATE with strings in the style of MM/DD/YY then use the INPUT() function with the MMDDYY informat to convert the string into a number.  You will need to create a new variable to store the number.

``birthdate_number = input(birthdate,mmddyy10.);``

Again either do not attach any format it to it or a format that displays the integer in the way you would like.

If you don't like the integers that SAS uses to store dates then explain what types of integers you want instead.

Discussion stats
• 8 replies
• 4053 views
• 8 likes
• 5 in conversation