i have excel file that contain variable like name age date.
and every date is in different format.
i import this date as character and now the problem is i dont no how to get date in one format.
data have;
input name age date;
datalines;
rahul 66 03dec2020
rohit 55 2020nov17
nisha 44 12/10/2020
;
run;
data want;
input name age date;
datalines;
rahul 66 03dec2020
rohit 55 17nov2020
nisha 44 10dec2020
;
run;
And the "ANY" informats will come to different results depending on locale. A date shown as xx/xx/xxxx can be MDY (e.g. USA) or DMY (Europe, Australia).
Please fix the obvious errors in the data step.
EDIT 1:
Some questions:
EDIT 2:
Working with the data you have posted:
data want;
set have(rename=(date = str_date));
attrib date length=8 format=date9.;
date = input(str_date, ?? anydtdte.);
if missing(date) then do;
date = input(str_date, ?? mmddyy10.);
end;
if missing(date) then do;
put "ERROR: Can't convert date in obs " _n_;
put _all_;
end;
run;
First comment: make sure that shown data step code runs. Yours has errors (fixed).
data have; input name :$10. age date :$15.; datalines; rahul 66 03dec2020 rohit 55 2020nov17 nisha 44 12/10/2020 ; data want (rename=(newdate=date)); set have; newdate = input(date,anydtdte32.); format newdate date9.; drop date; run;
The Anydtdte (any date ) informat will read many but not all common date formats. Problems typically come when using two-digit years as then a value like 01/02/03 can't tell which is actually the year (or day of the month or month in this case).
And the "ANY" informats will come to different results depending on locale. A date shown as xx/xx/xxxx can be MDY (e.g. USA) or DMY (Europe, Australia).
Thanks a ton
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.