BookmarkSubscribeRSS Feed
gnt1986
Calcite | Level 5


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.

3 REPLIES 3
ballardw
Super User

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.

art297
Opal | Level 21

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;

MumSquared
Calcite | Level 5

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

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 805 views
  • 0 likes
  • 4 in conversation