BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PravinMishra
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
PravinMishra
Quartz | Level 8

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;

View solution in original post

11 REPLIES 11
Reeza
Super User

What output are you expecting

1) Exact dates for your sample

2) SAS date with format applied or character variable

PravinMishra
Quartz | Level 8

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.

Ksharp
Super User

If that variable is date type variable , why not assign it another format mmddyyn10. ?

format  given_date  mmddyyn10.  ;

PravinMishra
Quartz | Level 8

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.

Reeza
Super User

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;

PravinMishra
Quartz | Level 8

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;

Reeza
Super User

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).

PravinMishra
Quartz | Level 8

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

Reeza
Super User

Date are given below

114010

14001

What dates are the above?

Jan 10, 2014

Jan 1, 2014?

PravinMishra
Quartz | Level 8

114010 date is 2014-01-10

Haikuo
Onyx | Level 15

I agree with . The inconsistency of your data is more problematic than choosing a proper informat. You have mentioned CYYDDD, so the first digit is "Century"? If yes, then it vaguely reflects PDJULIw. to me, maybe we can start from here if it does contain some information.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 7649 views
  • 3 likes
  • 4 in conversation