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 ;
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;
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;
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
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.