<?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: Flag medication switches chronologically in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908848#M358585</link>
    <description>&lt;P&gt;Do you mean that you want subjects that only took one medication to coded as SWITCH=0 instead of SWITCH=1?&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 16:50:18 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-12-19T16:50:18Z</dc:date>
    <item>
      <title>Flag medication switches chronologically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/907666#M358286</link>
      <description>&lt;P&gt;Hello SAS experts:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you give me a suggestion on how I can do the following chronologically (based on the Rx_date)?&amp;nbsp; The sample data is provided below. Thanks a lot in advance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step1: Count the number of switches among the drugs for each patient ; for examples, Pat_ID 201, should have switch count =8;Pat_ID 202 would have switch count=6 , and&amp;nbsp;Pat_ID 203 would have switch count=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step2: For patients never switched, flag them as the drug they were on; For example,&amp;nbsp;Pat_ID 203, would have a&amp;nbsp; Uflag='Stable' &amp;amp; DrugStable='DrugB';&amp;nbsp;Pat_ID 201 &amp;amp; 202 would have&amp;nbsp; Uflag='Switcher' &amp;amp; DrugSwitch='DrugC, DrugA,DrugC, DrugA, DrugDrugC, DrugB, DrugC';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 3. Output the last RX_Date record for each patient with the flags in Step 1 &amp;amp; 2 and retain the first Rx_Date for all&amp;nbsp; patients; while creating switch date fields to keep the switch dates for each switcher such as switch1, switch2, switch3,....;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 4: Count the number of 'Stable' patients for each drug;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input PAT_ID RX_DT : ddmmyy10. RX_Name $;&lt;BR /&gt;format RX_DT ddmmyy10.;&lt;BR /&gt;datalines;;&lt;BR /&gt;201 18/07/2013 DrugA&lt;BR /&gt;201 27/12/2013 DrugA&lt;BR /&gt;201 13/06/2013 DrugC&lt;BR /&gt;201 19/08/2013 DrugC&lt;BR /&gt;201 01/05/2014 DrugC&lt;BR /&gt;201 14/10/2013 DrugC&lt;BR /&gt;201 20/02/2014 DrugC&lt;BR /&gt;201 27/03/2014 DrugA&lt;BR /&gt;201 16/09/2013 DrugB&lt;BR /&gt;201 18/12/2013 DrugC&lt;BR /&gt;202 16/04/2014 DrugC&lt;BR /&gt;202 16/01/2014 DrugC&lt;BR /&gt;202 02/10/2013 DrugC&lt;BR /&gt;202 15/07/2013 DrugC&lt;BR /&gt;202 13/05/2013 DrugC&lt;BR /&gt;202 11/03/2014 DrugC&lt;BR /&gt;202 11/11/2013 DrugB&lt;BR /&gt;202 23/09/2013 DrugA&lt;BR /&gt;202 05/08/2013 DrugA&lt;BR /&gt;202 24/06/2013 DrugA&lt;BR /&gt;203 11/12/2014 DrugB&lt;BR /&gt;203 11/09/2015 DrugB&lt;BR /&gt;203 23/09/2016 DrugB&lt;BR /&gt;203 05/08/2017 DrugB&lt;BR /&gt;203 24/06/2013 DrugB&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=have;&lt;BR /&gt;by pat_id rx_dt;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 21:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/907666#M358286</guid>
      <dc:creator>Emma22</dc:creator>
      <dc:date>2023-12-12T21:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Flag medication switches chronologically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/907684#M358295</link>
      <description>&lt;P&gt;Please provide a clear and complete definition of exactly what makes a "switch".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One concern when discussing medication is that people are often on multiple medications and I don't see anything in that example data that allows telling when different medication is just that, different for a different diagnosis. So "switch" is not at all clear to me.&lt;/P&gt;
&lt;P&gt;So you have to walk us through exactly what steps you are using to get a count of 8 for Pat_id = 201. If I count "change" of drug I only see 4. So there must be some other rules that you have not provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exactly how to expect to use a variable like this later : DrugSwitch='DrugC, DrugA,DrugC, DrugA, DrugDrugC, DrugB, DrugC'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And Step 3 you need to provide an actual example of the data set you expect as I don't follow that at all.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 23:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/907684#M358295</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-12T23:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Flag medication switches chronologically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/907703#M358310</link>
      <description>&lt;P&gt;This looks like homework.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What have you tried so far?&amp;nbsp; If you show your code, and the results produced, we can advise.&amp;nbsp; We can help you own the task,&amp;nbsp; instead of the opposite.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 05:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/907703#M358310</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-12-13T05:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Flag medication switches chronologically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908735#M358564</link>
      <description>&lt;P&gt;Thank you for your questions. I would like to define a 'switch' as any change different from the original drug. For example, consider pat_id201, who started with DrugC, then switched to Drug A, and later reverted to DrugC. In this case, I would define that patient 201 had 2 switches during the period from June 2013 through Aug 2013.&lt;BR /&gt;My aim is to maintain the history of movements among drugs and allow users to define a time period based on RX_DT to analyze the number of switches per patient and counts of patients for each drug within the drug group based on a user-defined period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For simplicity, all drugs in the provided sample data belong to the same drug group, and there is no need to consider other diagnosis-related variables. Thanks a lot!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 22:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908735#M358564</guid>
      <dc:creator>Emma22</dc:creator>
      <dc:date>2023-12-18T22:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: Flag medication switches chronologically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908754#M358566</link>
      <description>&lt;P&gt;Sort the data by PAT_ID and RX_DT but process the data by PAT_ID and RX_NAME.&amp;nbsp; You will need to add the NOTSORTED keyword to the BY statement.&amp;nbsp; Then just count the number of FIRST.RX_NAME records.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
  by pat_id px_dt;
run;

data want;
  set have ;
  by pat_id rx_name notsorted;
  if first.pat_id then switch=0;
  switch+first.rx_name;
  if last.pat_id;
  keep pat_id switch;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Resutl:&lt;/P&gt;
&lt;PRE&gt;Obs    PAT_ID    switch

 1       201        5
 2       202        3
 3       203        1
&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2023 02:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908754#M358566</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-19T02:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Flag medication switches chronologically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908846#M358584</link>
      <description>Thank you for your help, Tom. The result won't show the proper results for the switch count unless we add and "else" before "switch+first.rx_name;"&lt;BR /&gt;&lt;BR /&gt;Thanks, Tom</description>
      <pubDate>Tue, 19 Dec 2023 16:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908846#M358584</guid>
      <dc:creator>Emma22</dc:creator>
      <dc:date>2023-12-19T16:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Flag medication switches chronologically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908848#M358585</link>
      <description>&lt;P&gt;Do you mean that you want subjects that only took one medication to coded as SWITCH=0 instead of SWITCH=1?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 16:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908848#M358585</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-19T16:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Flag medication switches chronologically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908849#M358586</link>
      <description>&lt;P&gt;Yes, that's my hope at the end. I want to be able to flag patients as switchers and non-switcher (stable) at a given date. For example,&amp;nbsp; on July,1, 2013.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the beginning, I was just hoping to count how many times each patient switched and then sum up the total number of switches by pat_id before I use proc freq to get the distribution of the patients among drugs at a given date;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much again!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 16:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-medication-switches-chronologically/m-p/908849#M358586</guid>
      <dc:creator>Emma22</dc:creator>
      <dc:date>2023-12-19T16:59:35Z</dc:date>
    </item>
  </channel>
</rss>

