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.

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