Dear Experts.
I am facing an issue while converting the below date (given as example) to the date format yymmdd10.
Input Date : Wed Feb 03 00:00:00 CET 2016
Output Date: 2016-02-03 (As Expected)
I tired to change the input date with ANYDTDTE informat (using the INPUT function as date is coming from macro variable)and then tried to change it to YYMMdd10. format but it did not work out.
Regards,
Gulshan
Hello Gulshan,
If you only need the date, please try this:
%let d=Wed Feb 03 00:00:00 CET 2016;
data _null_;
d=input(cats(scan("&d",3),scan("&d",2),scan("&d",-1)), date9.);
put d= yymmdd10.;
run;
If you need the full datetime information, I suggest this:
data _null_;
dt=input(cats(scan("&d",3),scan("&d",2),scan("&d",-1)||':'||scan("&d",4)), datetime.);
d=datepart(dt);
put dt= datetime19.;
put d= yymmdd10.;
run;
What does not work mean?
Please post your code and log including any errors you received.
Hello Gulshan,
If you only need the date, please try this:
%let d=Wed Feb 03 00:00:00 CET 2016;
data _null_;
d=input(cats(scan("&d",3),scan("&d",2),scan("&d",-1)), date9.);
put d= yymmdd10.;
run;
If you need the full datetime information, I suggest this:
data _null_;
dt=input(cats(scan("&d",3),scan("&d",2),scan("&d",-1)||':'||scan("&d",4)), datetime.);
d=datepart(dt);
put dt= datetime19.;
put d= yymmdd10.;
run;
Perhaps you're not telling the whole story.
34 %put NOTE: &=sysvlong;
NOTE: SYSVLONG=9.04.01M3P062415
35 data _null_;
36 input str $40. @1 date & ANYDTDTE.;
37 format date YYMMdd10. /*worddate.*/;
38 put (_all_)(/=);
39 cards;
str=Wed Feb 03 00:00:00 CET 2016
date=2016-02-03
Hi Data_null__,
Thanks for the solution.
Regards,
Gulshan
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.