BookmarkSubscribeRSS Feed
ravindra2
Fluorite | Level 6

hi friend,

 

i have one new task i have to convert some data into iso8601 format can any one help me?

 

data sample;
input year month date time $;
cards;
2014 6 10 08:12
2014 6 11 08:16
2014 6 13 08:34
2014 6 14 08:12
2014 6 15 08:19
2014 6 16 08:45
;

 

this is the data how can i convert into iso8601 format?

3 REPLIES 3
andreas_lds
Jade | Level 19

Use the appropriate informat to create a sas datetime variable. Then assign the format iso8601dt to the created variable. Job done.

Jagadishkatam
Amethyst | Level 16

Hope this helps

 

data sample;
input year month date time $;
day=input(catx('-',put(date,best.),put(month,best.),put(year,best.)),ddmmyy10.);
date2=put(dhms(day,0,0,input(time,time5.)),E8601DT.);
cards;
2014 6 10 08:12
2014 6 11 08:16
2014 6 13 08:34
2014 6 14 08:12
2014 6 15 08:19
2014 6 16 08:45
;
Thanks,
Jag
Reeza
Super User

If you can read it in as a TIME instead this becomes fairly easy:

 

 

data sample;
input year month date time : time.;
format time time.;
cards;
2014 6 10 08:12
2014 6 11 08:16
2014 6 13 08:34
2014 6 14 08:12
2014 6 15 08:19
2014 6 16 08:45
;



data want;
set sample;

time_want = dhms(mdy(month, date, year), 0, 0, time);
format time_want E8601DT.;
time_want_char = put(time_want, E8601DT.);

run;

proc print;run;

If you already have time as character you can convert it using the following and then replacing time in the code above with time_num. 

 

time_num=input(time, time.);