I have a large file of persons who have been drug-tested. The drug test dates have been arranged in chronological order, and the subjects in alpha order.
I need to calculate the number of days between the first and last drug tests for each person, and then calculate the mean days between first and last test for all persons in the file.
I have tried the lag function various ways to do this, but cannot develop a syntax that works for this calculation.
Thanks for your help. The following is an example of one case.
DOB DRUG TEST DATE
This topic has been locked.
5 replies Latest Post - 2013-01-04T17:58:05Z by SystemAdmin
Pinned topic Calculation of dates between lab tests
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2013-01-04T17:58:05Z at 2013-01-04T17:58:05Z by SystemAdmin
Re: Calculation of dates between lab tests2012-12-26T18:34:26Z in response to SystemAdminDo you have a unique identifier for each case? If you do, I think you could sort your cases by your ID and drug test date, then use the AGGREGATE function to acquire the first and last test date for each unique case.
DATASET DECLARE test.
Then you can do your date computations.
Re: Calculation of dates between lab tests2013-01-04T16:41:32Z in response to SystemAdminHi storm v:
The solution you provided worked well for first and last lab tests for each subject.
I need now to calculate days between each test for each subject.
Is there a way to do this?
Thanks again for your help.
Re: Calculation of dates between lab tests2013-01-04T17:58:05Z in response to SystemAdminYou could restructure your data file so you have a single line of data for each subject. Once you have all the dates associated with a single case id on one line, you can compute the difference for each test date. The easiest way to do this is to use the restructure wizard - under "Data" choose "Restructure" and follow through the steps. The wizard will also allow you to paste and modify your syntax as needed.