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

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
jimbarbour
Meteorite | Level 14

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

 

View solution in original post

8 REPLIES 8
jimbarbour
Meteorite | Level 14

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

 

ballardw
Super User

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

jimbarbour
Meteorite | Level 14

@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

RAVI2000
Lapis Lazuli | Level 10
Yes, I need the Integer.
jimbarbour
Meteorite | Level 14

@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

Kurt_Bremser
Super User

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

Tom
Super User Tom
Super User

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 4053 views
  • 8 likes
  • 5 in conversation