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

i.e first # of days (difference)  will be missing and the 2nd will be difference of Jan 22, 2020-Jan 01, 2020 and so on by ID
ID       Date                   # of days (difference)
1       Jan 01, 2020           
1       Jan 22, 2020
1       Feb 02, 2020
2      Jan 01, 2020
2      Jan 24, 2020
2      Feb 12, 2020

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
set have;

by id;

num_days = dif(date);

if first.id then call missing(num_days);

run;

Use the DIF() function. 

 


@mahossain wrote:

i.e first # of days (difference)  will be missing and the 2nd will be difference of Jan 22, 2020-Jan 01, 2020 and so on by ID
ID       Date                   # of days (difference)
1       Jan 01, 2020           
1       Jan 22, 2020
1       Feb 02, 2020
2      Jan 01, 2020
2      Jan 24, 2020
2      Feb 12, 2020


 

View solution in original post

2 REPLIES 2
Reeza
Super User
data want;
set have;

by id;

num_days = dif(date);

if first.id then call missing(num_days);

run;

Use the DIF() function. 

 


@mahossain wrote:

i.e first # of days (difference)  will be missing and the 2nd will be difference of Jan 22, 2020-Jan 01, 2020 and so on by ID
ID       Date                   # of days (difference)
1       Jan 01, 2020           
1       Jan 22, 2020
1       Feb 02, 2020
2      Jan 01, 2020
2      Jan 24, 2020
2      Feb 12, 2020


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 672 views
  • 0 likes
  • 2 in conversation