Hi,
I am facing an issue regarding date conversion. I have a date which is in CYYDDD format It's nothing but a JULIAN format of the date.
Date are given below
114010
14001
I need to convert this date into YYYYMMDD format But I can't see any function which can help to convert it required format.
I am using below method to convert it.which helping me to convert 14001 in req format
req_date=tranwrd(put(dhms(input(put(given_date,6.),JULIAN6.),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');
Please let me know how to convert first julian date
Thanks for your help and it's really helpfull.I achieved it by doing below.
Let me if you see any loophole in my code.
data auth;
input AU_TRANS_DATE_JUL;
datalines;
114010
14010
;
run;
data req_date;
set auth(keep=AU_TRANS_DATE_JUL reqt_hh reqt_mm reqt_ss);
if AU_TRANS_DATE_JUL>100000 then
auth_trans_date=tranwrd(put(dhms(datejul(1900000+AU_TRANS_DATE_JUL),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');
else
auth_trans_date=tranwrd(put(dhms(input(put(AU_TRANS_DATE_JUL,6.),JULIAN6.),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');
run;
What output are you expecting
1) Exact dates for your sample
2) SAS date with format applied or character variable
I am expecting an output in YYYY MM DD HH MM SS format.HH MM SS will taken care by reqt_hh,reqt_mm,reqt_ss variable.Let me know if you have any query.
If that variable is date type variable , why not assign it another format mmddyyn10. ?
format given_date mmddyyn10. ;
Hi,
It's in Julian format with six digit. there are function like Datejul which will help to convert it into Date.But that is for 5 0r 7 digit not for 6 digit.
You have inconsistent data which makes it manual, especially if both of your example dates are in 2014.
Here's a manual way, basically remove the first digit as it doesn't seem to add any information.
data have;
input given_date @@;
cards;
114010
14001
;
run;
data want;
set have;
char_var=put(given_date, 6. -l);
if length(char_var)>5 then char_var=substr(char_var, 2);
req_date=input(char_var,JULIAN7.);
format req_date date9.;
run;
Thanks for your help and it's really helpfull.I achieved it by doing below.
Let me if you see any loophole in my code.
data auth;
input AU_TRANS_DATE_JUL;
datalines;
114010
14010
;
run;
data req_date;
set auth(keep=AU_TRANS_DATE_JUL reqt_hh reqt_mm reqt_ss);
if AU_TRANS_DATE_JUL>100000 then
auth_trans_date=tranwrd(put(dhms(datejul(1900000+AU_TRANS_DATE_JUL),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');
else
auth_trans_date=tranwrd(put(dhms(input(put(AU_TRANS_DATE_JUL,6.),JULIAN6.),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');
run;
My only concern is are you sure that
14010 isn't January 10, 1914?
I don't know your data, but that's still a valid birthdate in my data.
(Also, it changed from initial example: 14010 vs 14001).
I agreed on your concern.Even I have the same concern.But the data on which I am working belong to 2014 January month data.
Due to which I am feeling little bit comfortable with the conversion.
I appreciate your concern
Date are given below
114010
14001
What dates are the above?
Jan 10, 2014
Jan 1, 2014?
114010 date is 2014-01-10
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.