BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
HI i have a data set i want the doff between two dates. here is the data set;

data x;
input date ddmmyy10.;
cards;
12/10/1980
09/08/1983
29/08/1985
19/09/1989
19/08/1989
;
i want the difff between two dates
4 REPLIES 4
Cynthia_sas
Diamond | Level 26
Hi:
The difference between dates on each observation??? You might investigate the LAG function.

cynthia
Doc_Duke
Rhodochrosite | Level 12
If you want all possible difference between the dates, you can use PROC SQL and do an outer join of x to x (This is often called a Cartesian Product).

*untested code;
PROC SQL;
CREATE TABLE AllDiff AS
SELECT a.date as date1,
b.date as date2,
Diff as date1-date1
FROM x AS a
OUTER JOIN x AS b;
QUIT;
RUN;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You may want to explore the SAS DATA STEP functions INTCK and also INTNX; the latter function can be helpful with generating DATE and DATETIME variable values, based on other variables. For example, you can use a DATA STEP DO/END loop to generate (OUTPUT) SAS observations for each date value in a date-range, say for the past 12 months or 26 weeks.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
after create the data x;
data y;
retain diff 0 old 0 date 0;
old=date;
set x;
diff=date-old;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 4 replies
  • 2199 views
  • 0 likes
  • 5 in conversation