BookmarkSubscribeRSS Feed
chirag1401
Calcite | Level 5

Hi all,

As an intermediate user of SAS 9.4, I have tried many different ways to find solution.  Below is sample data which is defined as below. So this is basically patient's journey to clinic starting with a particular diagnosis date and ends with treatment. Trying to find days between initial diagnosis to either tx1 or tx2 or both. also days between each diagnosis and each treatment to have sum of entire treatment from that initial diagnosis. Tried many different ways including SQL min-max, data step first. last., even tried Difference and LAG, lead dates but difference is not calculated correctly. This is a sample dataset. Greatly appreciate your suggestions.  Thanks.

Sum days= Last tx day - initial dx day

dx to dx= last dx date- prev. dx date

tx1 to dx= tx1 date-prev. dx date

tx2 to dx= tx2 date-prev. dx date

tx to tx= tx date-prev. tx date

txb4dx= dx date-tx date (example ID 5)

variables such as dx1_ct, tx1_ct, tx2_ct are total distinct dates for individual variable

I would also like to know if there is overlap between two treatments (yes/no)

 

 Have      
IDDx1dateTX1dateTX2dateDX1_ctTX1_ctTX2_ct
1  8/7/2018201
18/6/2018  201
18/7/2018  201
2   200
22/16/2018  200
23/1/2018  200
3   730
34/2/2018  730
34/2/20184/2/2018 730
34/16/2018  730
34/16/20184/16/2018 730
34/19/2018  730
34/30/2018  730
34/30/20184/30/2018 730
35/30/2018  730
310/1/2018  730
310/31/2018  730
4   225
4  7/31/2018225
4  8/26/2018225
4  9/28/2018225
4  11/1/2018225
4  12/8/2018225
44/20/2018  225
44/20/20184/20/2018 225
411/1/2018  225
411/1/201811/1/2018 225
5   1101
5  12/8/20181101
5 1/15/2018 1101
5 2/14/2018 1101
5 2/16/2018 1101
5 3/14/2018 1101
5 3/19/2018 1101
5 3/21/2018 1101
5 4/20/2018 1101
5 4/23/2018 1101
52/20/20185/21/2018 1101
5 5/23/2018 1101

 

 want            
IDDx1dateTX1dateTX2dateDX1_ctTX1_ctTX2_cttxB4dxdx1todx1tx1todxtx2todxtx to txSum Days
1  8/7/2018201      
18/6/2018  201      
18/7/2018  201 1 1 1
2   200      
22/16/2018  200      
23/1/2018  200 14   14
3   730      
34/2/2018  730      
34/2/20184/2/2018 730  0   
34/16/2018  730      
34/16/20184/16/2018 730 150   
34/19/2018  730 4    
34/30/2018  730      
34/30/20184/30/2018 730 120  45
35/30/2018  730 31    
310/1/2018  730 125    
310/31/2018  730 31    
4   225      
4  7/31/2018225   103  
4  8/26/2018225    27 
4  9/28/2018225    34 
4  11/1/2018225    35 
4  12/8/2018225    38233
44/20/2018  225      
44/20/20184/20/2018 225 00   
411/1/2018  225      
411/1/201811/1/2018 225 00   
5   1101      
5  12/8/20181101      
5 1/15/2018 110137     
5 2/14/2018 1101    31 
5 2/16/2018 1101    3 
5 3/14/2018 1101  23 27 
5 3/19/2018 1101    6 
5 3/21/2018 1101    3 
5 4/20/2018 1101    31 
5 4/23/2018 1101    4 
52/20/20185/21/2018 1101    29 
5 5/23/2018 1101    393
5 REPLIES 5
HarrySnart
SAS Employee

Hi @chirag1401 , Have you tried the INTCK function? https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html. You can set the time difference in days between the two dates. 

chirag1401
Calcite | Level 5

Yes, I have tried INTCK function as well without any success.  

andreas_lds
Jade | Level 19

Providing the data you have in usable form (a data step using datalines/cards) makes it easier for us to provide help.

And please explain which tx day should be used if both are not missing.

Sum days= Last tx day - initial dx day

 

chirag1401
Calcite | Level 5

Apologies.  TX1 should be used as treatment day if both are not missing.

chirag1401
Calcite | Level 5

Here is the data.

 

data Have
input ID $ Dx1date TX1date TX2date DX1_ct TX1_ct TX2_ct;
datalines;

 

1 8/7/2018 2 0 1
1 8/6/2018 2 0 1
1 8/7/2018 2 0 1
2 2 0 0
2 2/16/2018 2 0 0
2 3/1/2018 2 0 0
3 7 3 0
3 4/2/2018 7 3 0
3 4/2/2018 4/2/2018 7 3 0
3 4/16/2018 7 3 0
3 4/16/2018 4/16/2018 7 3 0
3 4/19/2018 7 3 0
3 4/30/2018 7 3 0
3 4/30/2018 4/30/2018 7 3 0
3 5/30/2018 7 3 0
3 10/1/2018 7 3 0
3 10/31/2018 7 3 0
4 2 2 5
4 7/31/2018 2 2 5
4 8/26/2018 2 2 5
4 9/28/2018 2 2 5
4 11/1/2018 2 2 5
4 12/8/2018 2 2 5
4 4/20/2018 2 2 5
4 4/20/2018 4/20/2018 2 2 5
4 11/1/2018 2 2 5
4 11/1/2018 11/1/2018 2 2 5
5 1 10 1
5 12/8/2018 1 10 1
5 1/15/2018 1 10 1
5 2/14/2018 1 10 1
5 2/16/2018 1 10 1
5 3/14/2018 1 10 1
5 3/19/2018 1 10 1
5 3/21/2018 1 10 1
5 4/20/2018 1 10 1
5 4/23/2018 1 10 1
5 2/20/2018 5/21/2018 1 10 1
5 5/23/2018 1 10 1
;
run;

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!

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
  • 5 replies
  • 401 views
  • 0 likes
  • 3 in conversation