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

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_IDreceiveDateStartDateCloseDateMortalityFINAL
18/12/20187/16/201812/13/20180.108813986
22/12/20191/21/20196/13/20190.200070493
39/18/20188/8/201812/20/20180.10570713
47/13/20187/2/20181/4/20190.118079133
52/24/20199/24/20183/1/20190.075649992
67/31/20184/23/20188/24/20180.078485479

 

DESIRED DATE:

group_IDreceiveDateStartDateCloseDateMortalityFINALDx_Date
19/27/20187/16/201812/13/20180.108813986early
22/12/20191/21/20196/13/20190.200070493early
39/18/20188/8/201812/20/20180.10570713Mid
47/13/20187/2/20181/4/20190.118079133early
510/24/20189/24/20183/1/20190.075649992Late
67/31/20184/23/20188/24/20180.078485479Late

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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;
edison83
Obsidian | Level 7

It worked perfectly, thanks a lot man!!!

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 2 replies
  • 1028 views
  • 1 like
  • 2 in conversation