I have a character variable which contains dates like: Mon Jul 24 02:48:17 -0700 2017
How can I extract the usable(date,month,year) date and save it as numeric date. I know how to do it by using SUBSTR function and then concatenating everything together. But I want to know a easier and quick way. I tried using ANYDTDTE informat to read it, but got blank values. Let me know if there is any simpler way to read this date.
I had a quick glance at the SAS informats:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001239776.htm
My quick glance didn't turn up a suitable informat. Perhaps I missed it.
This works with your given input. Not sure if it's any different than your approach?
data test;
cdate='Mon Jul 24 02:48:17 -0700 2017';
date=input(
cats(
scan(cdate,3,' '),
scan(cdate,2,' '),
scan(cdate,-1,' ')
),date9.);
format date date9.;
run;
I had a quick glance at the SAS informats:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001239776.htm
My quick glance didn't turn up a suitable informat. Perhaps I missed it.
This works with your given input. Not sure if it's any different than your approach?
data test;
cdate='Mon Jul 24 02:48:17 -0700 2017';
date=input(
cats(
scan(cdate,3,' '),
scan(cdate,2,' '),
scan(cdate,-1,' ')
),date9.);
format date date9.;
run;
This is awesome. Although I was looking for some informat which can read the string without scanning it. Additionally, I changed the code a bit to keep the same variable in dataset.
data test(drop=cdate rename=(date=cdate));
cdate='Mon Jul 24 02:48:17 -0700 2017';
date=input(
cats(
scan(cdate,3,' '),
scan(cdate,2,' '),
scan(cdate,-1,' ')
),date9.);
format date date9.;
run;
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.