The following macro dtcn helps in conversion of character date and time to numeric date and time.
%macro dtcn(indt,dtmn);
length dt1 $10 tm1 $6 dt1n $20;
if index(&indt,'T') ne 0 then do;
dt1 = scan(&indt,1,'T');
tm1 = scan(&indt,2,'T');
if dt1 ne '' and tm1 ne '' then dt1n = put(input(dt1,yymmdd10.),date9.)' 'trim(left(tm1));
if dt1 ne '' and tm1 ne '' then &dtmn = input(dt1n,datetime15.);
else if dt1 ne '' and tm1 eq '' then &dtmn =input(put(input(dt1,yymmdd10.),date9.),date9.);
end;
else &dtmn = .;
%mend;
data date;
xxstdtc='2009-01-02T17:30';
run;
length dt1 $10 tm1 $6 dt1n $20;
if index(&indt,'T') ne 0 then do;
dt1 = scan(&indt,1,'T');
tm1 = scan(&indt,2,'T');
if dt1 ne '' and tm1 ne '' then dt1n = put(input(dt1,yymmdd10.),date9.)' 'trim(left(tm1));
if dt1 ne '' and tm1 ne '' then &dtmn = input(dt1n,datetime15.);
else if dt1 ne '' and tm1 eq '' then &dtmn =input(put(input(dt1,yymmdd10.),date9.),date9.);
end;
else &dtmn = .;
%mend;
data date;
xxstdtc='2009-01-02T17:30';
run;
data date1;
format xxstdtn datetime15.;
set date;
%dtcn(xxstdtc, xxstdtn);
run;
No comments:
Post a Comment