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
SAS Super FREQ
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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