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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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