Hello SAS community,
I need your help with the following. Any help is appreciated.
Raw data:-
ID | StartDate | Drug |
1 | 9-May-12 | A |
1 | 10-May-12 | A |
1 | 10-May-12 | B |
1 | 30-May-12 | B |
1 | 31-May-12 | A |
1 | 1-Jun-12 | A |
1 | 2-Jun-12 | B |
1 | 30-Jun-12 | C |
1 | 3-Jul-12 | A |
1 | 27-Jul-12 | A |
1 | 28-Jul-12 | D |
2 | 17-May-12 | A |
2 | 22-May-12 | B |
2 | 25-May-12 | B |
2 | 1-Jun-12 | C |
2 | 2-Jun-12 | D |
2 | 3-Jun-12 | B |
3 | 26-Jun-12 | A |
3 | 29-Jun-12 | A |
3 | 27-Jul-12 | B |
3 | 25-Aug-12 | B |
4 | 26-Jun-12 | A |
4 | 27-Jun-12 | B |
4 | 28-Jun-12 | C |
4 | 25-Aug-12 | A |
4 | 26-Aug-12 | B |
4 | 27-Aug-12 | B |
I want to get the results based on line of drug therapy.
Output should look like
ID | 1st line | 2nd line | 3rd line |
1 | A + B | A + C | A+D |
2 | A+B | B+C+D | . |
3 | A | B | . |
4 | A+B+C | . | . |
1st line:
2nd line:
3rd line:
In other words,
1st line = First drug + all drugs given within 10 days of 1st drug start date for ex. suppose that A+B+C are with in 1st 10 days.
2nd line = if person gets any other drugs than the one given in 1st line For ex. C drug is added to drug course then 2nd line is all the drugs given 3 days prior to C drug start date and 10 days after C drug start date.
3rd Line = if person gets any other drugs than the one given in 2nd or 1st line For ex. D drug is added to drug course then 3rd line is all the drugs given 3 days prior to C drug start date and 10 days after D drug start date.
and so on.
I hope I am clear about my question.
Please Help.
You should provide an example of what the outcome would look like for that example data.
"Course: Any drug in the period 3 days prior to start date to 10 days after start date" isn't really clearly defined as you have a "start date" on every record.
@shasank It's an interesting problem, but I find your explanation of the logic little inadequate. Hmm part of the reason is perhaps I am not smart. Either way, Please clarify the following
q1. does every obs for each id have a line starting from line1......lineN?
q2. So the number of lines for each id varies? for example, 9 for ID 1 and 4 for ID 3?
q3 So when processing the last few obs(perhaps) for a particular id, the look up can only be prior dates for the reason there won't dates to look ahead
Hmm still not clear. Anyway, can you explain the look up for the just the one row
ID | 1st line | 2nd line | 3rd line |
1 | A + B | A + C | A+D |
How you got the above and from where referring to your HAVE dataset?
For ID one there has to be 1st line----9th line?
Hey, I am writing to apologise that I didn't get head start on your req as my brain isn't thinking well. I am off to classes at my college right now. But don;t worry, I will sincerely take a look later. Either way, You can be 100% percent, KSharp @xia keshan will fire your needed answer the moment he sees this thread even if no else responds, He is my role model. I wish I could be like him. So wait for a while!
@shasank I am afraid I haven't got a clear understanding of your requirement at all to even get a head start to let my brain and fingers do the rest. Unfortunately, This is after looking into your description multiple times. Personally, I am disappointed too for not even being able to give a go. Well, this is where communication matters most. One of us isn't making it easy to help each other. So sorry!
@Astounding Can you help me with this one?
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.