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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.