## Relative Julian format

Solved
Occasional Contributor
Posts: 16

# Relative Julian format

Hello,

I have a problem with reading the date values. The source sends us the data in relative Julian format (ddd) with the date relative to the first day of the previous year(1/1/2014 now).  So when we roll into 2016, it will become 1/1/2015 to the present day.

I created a sample code to see how I can read the below day's to be converted to a date format. For example lets assume the first value 345 is the 345th day starting from 01/01/2014 and the autopay variable should give me the value in date9 format.

Would you know what function can I use to convert this days (ddd) into a format like date9 so that business users understand the date when they read the report. The below would how the autopay values looks like in my dataset.

data test;

input autopay ;

datalines ;

345

491

492

493

494

499

500

503

504

510

511

;

run ;

Accepted Solutions
Solution
‎06-22-2015 11:22 AM
Super User
Posts: 23,342

## Re: Relative Julian format

Use the INTNX function to get the starting date, ie the Jan 1, 2014.

Then you can add the autopay to the date and format to the SAS date.

data test;

input autopay ;

datalines ;

345

491

492

493

494

499

500

503

504

510

511

;

run ;

data want;

set test;

start_date = intnx('year', today(), -1, 'b');

date_want = autopay + start_date;

format start_date date_want date9.;

run;

All Replies
Solution
‎06-22-2015 11:22 AM
Super User
Posts: 23,342

## Re: Relative Julian format

Use the INTNX function to get the starting date, ie the Jan 1, 2014.

Then you can add the autopay to the date and format to the SAS date.

data test;

input autopay ;

datalines ;

345

491

492

493

494

499

500

503

504

510

511

;

run ;

data want;

set test;

start_date = intnx('year', today(), -1, 'b');

date_want = autopay + start_date;

format start_date date_want date9.;

run;

Posts: 5,482

## Re: Relative Julian format

I agree, except for the calculation of date_want. It should be:

date_want = intnx("DAY", start_date, autopay - 1);

Minus one is because I assume that January first is Julian day = 1.

Also, it would probably be safer to use the creation date (or last modification date) of the data file instead of Today() to derive the starting date.

PG

PG
Occasional Contributor
Posts: 16

## Re: Relative Julian format

Thanks PG. It certainly made a difference and yielded more accurate answer as when I gave the autopay as 007 and your code gave the answer as 07JAN2014 and Reez's code was giving 08JAN2014.

🔒 This topic is solved and locked.