BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sascode
Quartz | Level 8

Hello, i have a dataset as follows:
data have;
length number $ 54;
input number $;
datalines;
44991.65
run;

This number which is coming as character in SAS, represents in excel 

3/6/23 3:29 PM

So the question is, how to extract only the date part from this number?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Fix your Excel file so that the column with the DATETIME values does not have any cells with character strings.  Then the value will come as a numeric DATETIME value.

 

If you can't fix it then you will have to convert it to a number and add the negative number that represents 30DEC1899 to adjust for the difference in how SAS and Excel number days.

The fraction of a day is ignored by the DATE format, but to remove it you can use the INT() function.  

 

date = int(input(number,32.)) + '30DEC1899'd ;
format date date9.;

Note that the longest string that the normal numeric informat can read is 32 characters, which should be longer than any string you get from Excel that represents an actual datetime value.  If you really have some other string that is 54 characters long then that is probably what is causing the actual dates to be converted to strings.

 

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Fix your Excel file so that the column with the DATETIME values does not have any cells with character strings.  Then the value will come as a numeric DATETIME value.

 

If you can't fix it then you will have to convert it to a number and add the negative number that represents 30DEC1899 to adjust for the difference in how SAS and Excel number days.

The fraction of a day is ignored by the DATE format, but to remove it you can use the INT() function.  

 

date = int(input(number,32.)) + '30DEC1899'd ;
format date date9.;

Note that the longest string that the normal numeric informat can read is 32 characters, which should be longer than any string you get from Excel that represents an actual datetime value.  If you really have some other string that is 54 characters long then that is probably what is causing the actual dates to be converted to strings.

 

 

sascode
Quartz | Level 8
It worked perfectly. That addition part is the key I was not considering.
Thank you.

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
  • 2 replies
  • 774 views
  • 1 like
  • 2 in conversation