<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Identifying medication changes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/893298#M352891</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/399969"&gt;@Nina4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Great questions!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These were my rules:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Baseline: drugs of the therapy 1 of a patient&lt;/P&gt;
&lt;P&gt;last_time: if a drug is stopped afterwards&lt;/P&gt;
&lt;P&gt;restart: a drug that has been taken before, but that had a break&lt;/P&gt;
&lt;P&gt;new_start: start of a drug, that has never been used before by that patient&lt;/P&gt;
&lt;P&gt;no_change: nothing changed to the therapy before&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you are right:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;add&lt;/P&gt;
&lt;P&gt;one_time: if a drug appears only once&lt;/P&gt;
&lt;P&gt;paused: if a drug has a break and is then restarted again&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope, this helps.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, it helps but&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Why is&amp;nbsp; &amp;nbsp;1/4/druga characterized as "last time" instead of "paused", given there is a subsequent 1/4/druga?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;What if the "one time" is at baseline?&amp;nbsp; &amp;nbsp;Which of those two status values do you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Sep 2023 13:01:52 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-09-08T13:01:52Z</dc:date>
    <item>
      <title>Identifying medication changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/892958#M352723</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with patients that have different therapies. In the therapies there are multiple medications. It all is in a long format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is in this format:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data your_dataset;
input PatientID TherapyID Drug $;
datalines;
1 1 DrugA
1 1 DrugB
1 1 DrugC
1 2 DrugA
1 2 DrugB
1 2 DrugC
1 3 DrugB
1 3 DrugC
1 4 DrugA
1 4 DrugC
1 4 DrugB
1 4 DrugD
2 5 DrugA
2 5 DrugD
2 7 DrugA
2 7 DrugC
3 6 DrugB
3 6 DrugE
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to identify, which drugs are newly started or finished within a patient, when they have a new therapy. And flag them accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solution example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 DrugA baseline&lt;/P&gt;&lt;P&gt;1 1 DrugB baseline&lt;/P&gt;&lt;P&gt;1 1 DrugC baseline&lt;/P&gt;&lt;P&gt;1 2 DrugA last_time&lt;/P&gt;&lt;P&gt;1 2 DrugB no_change&lt;/P&gt;&lt;P&gt;1 2 DrugC no_change&lt;/P&gt;&lt;P&gt;1 3 DrugB no_change&lt;/P&gt;&lt;P&gt;1 3 DrugC no_change&lt;/P&gt;&lt;P&gt;1 4 DrugA restart&lt;/P&gt;&lt;P&gt;1 4 DrugC no_change&lt;/P&gt;&lt;P&gt;1 4 DrugB no_change&lt;/P&gt;&lt;P&gt;1 4 DrugD new_start&lt;/P&gt;&lt;P&gt;2 5 DrugA baseline&lt;/P&gt;&lt;P&gt;2 5 DrugD last_time&lt;/P&gt;&lt;P&gt;2 7 DrugA no_change&lt;/P&gt;&lt;P&gt;2 7 DrugC new_start&lt;/P&gt;&lt;P&gt;3 6 DrugB baseline&lt;/P&gt;&lt;P&gt;3 6 DrugE baseline&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They could also have variables added with a binary value to it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, I have used this code, but there are multiple errors in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data drug_changes;
  set your_dataset;
  by PatientID;
  retain PrevPatientID PrevTherapyID FirstTherapyDrugs;
  
  if first.PatientID then do;
    PrevPatientID = .;
    PrevTherapyID = .;
    FirstTherapyDrugs = '';
  end;
  
  if PatientID ne PrevPatientID then do;
    PrevTherapyID = .;
    FirstTherapyDrugs = '';
  end;
  
  if TherapyID ne PrevTherapyID then do;
    if Drug ne '' then do;
      if PrevTherapyID ne . then do;
        action = 'Finished';
        output;
      end;
      if TherapyID = 1 then do; /* Check if it's the first therapy */
        FirstTherapyDrugs = catx('|', FirstTherapyDrugs, Drug); /* Concatenate drugs */
        action = 'First Start';
        output;
      end;
      else do;
        action = 'Started';
        output;
      end;
    end;
  end;
  
  PrevPatientID = PatientID;
  PrevTherapyID = TherapyID;
  
  if last.PatientID then do;
    if FirstTherapyDrugs ne '' then do;
      do i = 1 to countw(FirstTherapyDrugs, '|');
        Drug = scan(FirstTherapyDrugs, i, '|');
        action = 'First Start';
        output;
      end;
    end;
    if Drug ne '' then do;
      if TherapyID = 1 then do; /* Check if it's the first therapy */
        FirstTherapyDrugs = catx('|', FirstTherapyDrugs, Drug); /* Concatenate drugs */
        action = 'First Start';
        output;
      end;
      else do;
        action = 'Started';
        output;
      end;
    end;
  end;
  
  drop PrevPatientID PrevTherapyID FirstTherapyDrugs i;
run;

proc print data=drug_changes;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you so much for your help in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nina&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 15:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/892958#M352723</guid>
      <dc:creator>Nina4</dc:creator>
      <dc:date>2023-09-06T15:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying medication changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/892981#M352735</link>
      <description>&lt;P&gt;In terms of data what is "new"? How do we recognize that? And the same for "finish"? Rules are a good idea, otherwise we are guessing and that's seldom a good idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question about "last time". If it is "restarted" is it really a "last"?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 16:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/892981#M352735</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-06T16:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying medication changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/892988#M352739</link>
      <description>&lt;P&gt;What if a drug appears only once?&amp;nbsp; &amp;nbsp;Will you establish a new status&amp;nbsp; (say 'ONE TIME')?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what if that one time is for therapyid=1 (which I presume is how you identify status 'BASELINE')?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 16:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/892988#M352739</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-06T16:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying medication changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/893078#M352784</link>
      <description>&lt;P&gt;Great questions!&amp;nbsp;&lt;/P&gt;&lt;P&gt;These were my rules:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Baseline: drugs of the therapy 1 of a patient&lt;/P&gt;&lt;P&gt;last_time: if a drug is stopped afterwards&lt;/P&gt;&lt;P&gt;restart: a drug that has been taken before, but that had a break&lt;/P&gt;&lt;P&gt;new_start: start of a drug, that has never been used before by that patient&lt;/P&gt;&lt;P&gt;no_change: nothing changed to the therapy before&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But you are right:&amp;nbsp;&lt;/P&gt;&lt;P&gt;add&lt;/P&gt;&lt;P&gt;one_time: if a drug appears only once&lt;/P&gt;&lt;P&gt;paused: if a drug has a break and is then restarted again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope, this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 06:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/893078#M352784</guid>
      <dc:creator>Nina4</dc:creator>
      <dc:date>2023-09-07T06:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying medication changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/893298#M352891</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/399969"&gt;@Nina4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Great questions!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These were my rules:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Baseline: drugs of the therapy 1 of a patient&lt;/P&gt;
&lt;P&gt;last_time: if a drug is stopped afterwards&lt;/P&gt;
&lt;P&gt;restart: a drug that has been taken before, but that had a break&lt;/P&gt;
&lt;P&gt;new_start: start of a drug, that has never been used before by that patient&lt;/P&gt;
&lt;P&gt;no_change: nothing changed to the therapy before&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you are right:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;add&lt;/P&gt;
&lt;P&gt;one_time: if a drug appears only once&lt;/P&gt;
&lt;P&gt;paused: if a drug has a break and is then restarted again&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope, this helps.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, it helps but&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Why is&amp;nbsp; &amp;nbsp;1/4/druga characterized as "last time" instead of "paused", given there is a subsequent 1/4/druga?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;What if the "one time" is at baseline?&amp;nbsp; &amp;nbsp;Which of those two status values do you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 13:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/893298#M352891</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-08T13:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying medication changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/893302#M352892</link>
      <description>&lt;P&gt;You are right, with the new value paused and one_time the dataset should like like the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 DrugA baseline&lt;/P&gt;&lt;P&gt;1 1 DrugB baseline&lt;/P&gt;&lt;P&gt;1 1 DrugC baseline&lt;/P&gt;&lt;P&gt;1 2 DrugA paused&lt;/P&gt;&lt;P&gt;1 2 DrugB no_change&lt;/P&gt;&lt;P&gt;1 2 DrugC no_change&lt;/P&gt;&lt;P&gt;1 3 DrugB no_change&lt;/P&gt;&lt;P&gt;1 3 DrugC no_change&lt;/P&gt;&lt;P&gt;1 4 DrugA restart&lt;/P&gt;&lt;P&gt;1 4 DrugC no_change&lt;/P&gt;&lt;P&gt;1 4 DrugB no_change&lt;/P&gt;&lt;P&gt;1 4 DrugD new_start&lt;/P&gt;&lt;P&gt;2 5 DrugA baseline&lt;/P&gt;&lt;P&gt;2 5 DrugD last_time&lt;/P&gt;&lt;P&gt;2 7 DrugA no_change&lt;/P&gt;&lt;P&gt;2 7 DrugC new_start&lt;/P&gt;&lt;P&gt;3 6 DrugB baseline&lt;/P&gt;&lt;P&gt;3 6 DrugE baseline&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If one_time is at baseline, there should be one_time and also all other values should overrule baseline.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 13:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-medication-changes/m-p/893302#M352892</guid>
      <dc:creator>Nina4</dc:creator>
      <dc:date>2023-09-08T13:17:20Z</dc:date>
    </item>
  </channel>
</rss>

