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

Hi there. I am trying to subtract dates by row as shown here:

PlayerIDDate
100112JUN2020
100111JUN2020
100224AUG2020
100213JUL2020
100317MAY2021


What I want is this:

PlayerIDDateDateDiff
100112JUN2020.
100111JUN20201
100224AUG2020.
100213JUL202042
   


However, when I run this code

data table;
input PlayerID$ Date:date9.;

format Date date9.;
datalines;
1001 12JUN2021
1001 11JUN2021
1002 24AUG2020
1002 13JUL2020
;
pro sort data = table;

by PlayerID Date DESC;

run;

data datediff;
set table;
by PlayerID;
daydiff=abs(dif(Date));
if not first.PlayerID then output;
run;



It substracts the previous date regardless like this:

PlayerIDDateDateDiff
100112JUN2020 
100111JUN20201
100224AUG2020223
100213JUL202042
   

Any ideas on how to resolve this?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
daydiff=abs(dif(Date));
if first.PlayerID then daydiff=.;
--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26
daydiff=abs(dif(Date));
if first.PlayerID then daydiff=.;
--
Paige Miller
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1000 views
  • 0 likes
  • 2 in conversation