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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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