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

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 ;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

3 REPLIES 3
Reeza
Super User

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;

PGStats
Opal | Level 21

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
anoopm7
Calcite | Level 5

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.

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!

How to Concatenate Values

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.

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
  • 3 replies
  • 1654 views
  • 5 likes
  • 3 in conversation