Dates

Reply
Regular Contributor
Posts: 229

Dates

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
SAS Super FREQ
Posts: 8,642

Re: Dates

Hi:
The difference between dates on each observation??? You might investigate the LAG function.

cynthia
Valued Guide
Posts: 2,106

Re: Dates

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;
Super Contributor
Super Contributor
Posts: 3,174

Re: Dates

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.
N/A
Posts: 0

Re: Dates

after create the data x;
data y;
retain diff 0 old 0 date 0;
old=date;
set x;
diff=date-old;
run;
Post a Question
Discussion Stats
  • 4 replies
  • 381 views
  • 0 likes
  • 5 in conversation