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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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