Hello. I would like to calculate the number of days between dates but for column operations. I have the following data:
ID DATE
100 2020-07-01
100 2020-07-08
100 2020-07-13
110 2020-06-25
110 2020-06-29
I'd like to achieve data like:
ID DATE DAYS
100 2020-07-01 .
100 2020-07-08 7
100 2020-07-13 5
110 2020-06-25 .
110 2020-06-29 4
Can you help with solution?
data have;
input ID DATE :yymmdd10.;
format date yymmdd10.;
datalines;
100 2020-07-01
100 2020-07-08
100 2020-07-13
110 2020-06-25
110 2020-06-29
;
data want;
set have;
by ID;
days = dif(date);
if first.ID then days=.;
run;
data have;
input ID DATE :yymmdd10.;
format date yymmdd10.;
datalines;
100 2020-07-01
100 2020-07-08
100 2020-07-13
110 2020-06-25
110 2020-06-29
;
data want;
set have;
by ID;
days = dif(date);
if first.ID then days=.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.