data myfile;
set file1;
tdy=&pbd_date;
ckdt=CK007_dt;
age=tdy-ckdt;
format age date9.;
run;
In our database &pbd_date is a numeric that can be converted to a date format. ckdt is also a numeric
When I run the code, it initially produces numerics and a difference (ie 19663 - 19604 = 59)
If I format the age variable to a date9 I get wierd dates in the past (ie 19663 - 19604 = 29FEB1960)
If I format tdy ckdt age to date9 I get something like (01NOV2013-03SEP2013=29FEB1960)
I want the difference between 11/1/13 and 9/1/13 to be expressed in the actual date that is between the tdy and ck_dt.
When you subtract a date from another date you get the number of days between the values. Since SAS uses a base of 01Jan1960 for 'date' 0 then 59 days later is 29 Feb 1960.
If you need to get a count of specific intervals, such as months or weeks you want the INTCK function.
Not sure why you are calling your result "age" but, from what you described, does the following come close?:
%let pbd_date=19663;
data file1;
informat ck007_dt date9.;
input ck007_dt;
cards;
03sep2013
;
data myfile;
set file1;
tdy=&pbd_date;
ckdt=CK007_dt;
age=tdy+((tdy-ckdt)/2);
format age date9.;
run;
I would use intck ...
data dates;
format d_now dob date9.;
d_now=today();
dob="1jan1970"d;
age_years=intck('years',dob,d_now);
run;
proc print data=dates; run;
This gives:
Obs d_now dob age_years
1 05NOV2013 01JAN1970 43
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.