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


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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