Hello everyone.
I want to specify or tag groups based on the diagnostic date.
For each group on the experiment, i have the start date of the experiment and the close date.
I also have the date that the diagnostic was reported from this group.
Based on that information, i want to specify if the diagnostic occurred:
on the first 30 days after the start date (EARLY)
on the last 30 days before the close date (LATE)
and any other date between this period (Mid)
Here is an example of the date and how it would be the desired information (Dx_Date Collumn)
Just a reminder, this data has 1700 rows.
Thanks guys
ORIGINAL DATA:
group_ID | receiveDate | StartDate | CloseDate | MortalityFINAL |
1 | 8/12/2018 | 7/16/2018 | 12/13/2018 | 0.108813986 |
2 | 2/12/2019 | 1/21/2019 | 6/13/2019 | 0.200070493 |
3 | 9/18/2018 | 8/8/2018 | 12/20/2018 | 0.10570713 |
4 | 7/13/2018 | 7/2/2018 | 1/4/2019 | 0.118079133 |
5 | 2/24/2019 | 9/24/2018 | 3/1/2019 | 0.075649992 |
6 | 7/31/2018 | 4/23/2018 | 8/24/2018 | 0.078485479 |
DESIRED DATE:
group_ID | receiveDate | StartDate | CloseDate | MortalityFINAL | Dx_Date |
1 | 9/27/2018 | 7/16/2018 | 12/13/2018 | 0.108813986 | early |
2 | 2/12/2019 | 1/21/2019 | 6/13/2019 | 0.200070493 | early |
3 | 9/18/2018 | 8/8/2018 | 12/20/2018 | 0.10570713 | Mid |
4 | 7/13/2018 | 7/2/2018 | 1/4/2019 | 0.118079133 | early |
5 | 10/24/2018 | 9/24/2018 | 3/1/2019 | 0.075649992 | Late |
6 | 7/31/2018 | 4/23/2018 | 8/24/2018 | 0.078485479 | Late |
Hi @edison83 See if this helps
data have;
input group_ID (receiveDate StartDate CloseDate) (:mmddyy10.) MortalityFINAL;
format receiveDate StartDate CloseDate mmddyy10.;
cards;
1 8/12/2018 7/16/2018 12/13/2018 0.108813986
2 2/12/2019 1/21/2019 6/13/2019 0.200070493
3 9/18/2018 8/8/2018 12/20/2018 0.10570713
4 7/13/2018 7/2/2018 1/4/2019 0.118079133
5 2/24/2019 9/24/2018 3/1/2019 0.075649992
6 7/31/2018 4/23/2018 8/24/2018 0.078485479
;
data want;
set have;
length Dx_Date $5;
if StartDate<= receiveDate<=intnx('day',StartDate,30) then Dx_Date='Early';
else if intnx('day',CloseDate,-30)<=receiveDate<=CloseDate then Dx_Date='Late';
else if StartDate<= receiveDate<=CloseDate then Dx_Date='Mid';
run;
Hi @edison83 See if this helps
data have;
input group_ID (receiveDate StartDate CloseDate) (:mmddyy10.) MortalityFINAL;
format receiveDate StartDate CloseDate mmddyy10.;
cards;
1 8/12/2018 7/16/2018 12/13/2018 0.108813986
2 2/12/2019 1/21/2019 6/13/2019 0.200070493
3 9/18/2018 8/8/2018 12/20/2018 0.10570713
4 7/13/2018 7/2/2018 1/4/2019 0.118079133
5 2/24/2019 9/24/2018 3/1/2019 0.075649992
6 7/31/2018 4/23/2018 8/24/2018 0.078485479
;
data want;
set have;
length Dx_Date $5;
if StartDate<= receiveDate<=intnx('day',StartDate,30) then Dx_Date='Early';
else if intnx('day',CloseDate,-30)<=receiveDate<=CloseDate then Dx_Date='Late';
else if StartDate<= receiveDate<=CloseDate then Dx_Date='Mid';
run;
It worked perfectly, thanks a lot man!!!
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.