BookmarkSubscribeRSS Feed
ravindra2
Fluorite | Level 6

hi

i have a date and time data in character format how can i convert them to numeric in datastep

data sample;

input datetime $ 16.;

cards;

01-10-2018t10:15

01-10-2018t10:20

01-10-2018t10:20

;

 

date should be in date9 format and time should be in time5. 

please help me friend..

3 REPLIES 3
Shmuel
Garnet | Level 18

 

data sample;
  input datetime $ 16.;
  date = input(substr(datetime,1,10),ddmmyy10.);
time = input(substr(datetime,12,5),time5.);
format date date9. time time5.; cards; 01-10-2018t10:15 01-10-2018t10:20 01-10-2018t10:20 ;
run;
ravindra2
Fluorite | Level 6
Thank you its working
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, why do you have datetimes in that format in the first place.  It looks to me like a data error.  The T indicates that its an ISO date, however the format of ISOdates are:

YYYY-MM-DDTHH:MM

(Plus of course all the seconds, time zone etc.).  

Now your data has that kind of form but is all the wrong way round.  Go back to source and get it fixed.  This should be in your data transfer agreement/spec, otherwise you could be in all kinds of difficulties, e.g.

01-10-2018t10:15

10-01-2018t10:20

 

Are they both 01Oct, or is the second 10Jan?  Proper data formatting is key foundation in programming.

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
  • 3 replies
  • 889 views
  • 0 likes
  • 3 in conversation