BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PatrykSAS
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
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;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20
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;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 586 views
  • 0 likes
  • 2 in conversation