Dear,
In my data, the date time variable has the below values. I am using anydtdtm. informat to convert char to numeric, but it is working only for 2nd obs. Which informat should i use to output both rows. Thank you.
data have; input dtm $19.; datalines; 2016-06-02T14:44 2016-04-08 ; data want; set have; ndtm=input(dtm,anydtdtm.); format ndtm datetime18.; run;
Hello Kn,
I'm not sure which informat needed in this case . But here is an solutions , which may help to fulfill your request .
data want;
set have;
st=compress(substr(scan(dtm,3,'-'),3,1));
if st eq 'T' then dtm_ = substr(dtm,1,10);
else dtm_ =dtm;
ndtm=input(dtm_,anydtdte12.);
format ndtm date9.;
drop dtm_ st;
run;Thanks...
You need to be selective with respect to the length of dtm:
data have;
input dtm $19.;
datalines;
2016-06-02T14:44
2016-04-08
;
run;
data want;
set have;
if length(dtm) = 10
then mydtm = dhms(input(dtm,e8601da10.),0,0,0);
else mydtm = input(dtm,e8601dt19.);
format mydtm e8601dt19.;
run;
Note that the informat E8601DA10. is equivalent to YYMMDD10.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.