<?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 the number of subjects who had treatment switch in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269785#M53490</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51397"&gt;@ramchinna24﻿&lt;/a&gt;&amp;nbsp; Hi I have tried this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set new_have;/*sorted on pnr date*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by pnr;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Psoriasis' and type in ('Nonbiologic_systemic' 'Biologics')&amp;nbsp;&amp;nbsp; then f=1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Psoriasis' and type='Psoriasis' and lag(atc_code) ne atc_code then f=1;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Nonbiologic_systemic' and type in ('Biologics') then f=1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Nonbiologic_systemic' and type='Nonbiologic_systemic' and lag(atc_code) ne atc_code then f=1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type) in ('Nonbiologic_systemic' 'Psoriasis') and type='Biologics' then f=1; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Biologics' and type='Biologics' and lag(atc_code) ne atc_code then f=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;/* &amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(pnr) =pnr and lag(atc_code) ne atc_code then f=1; */&lt;BR /&gt;&lt;BR /&gt;run;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's ignoring the by group and adding flagging&amp;nbsp; for situations when patient by group is changes.&lt;/P&gt;</description>
    <pubDate>Wed, 11 May 2016 16:27:14 GMT</pubDate>
    <dc:creator>SASFREAK</dc:creator>
    <dc:date>2016-05-11T16:27:14Z</dc:date>
    <item>
      <title>Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269473#M53388</link>
      <description>&lt;P&gt;Hi SAS folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working on some reseach project using hospital visit data. I have to identify the subjects who had switched their treatment. the defination of treatment switch is like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Treatments are grouped by topical, non-biologic systemic, and biologic. A switching event is defined as the withdrawal of a medication that was not dispensed at the time of the last treatment withdrawal. There is a hierarchy, with biologics at the top, then non-bio systemics, then topical.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If a patient is first observed withdrawing a topical, any withdrawal of a treatment after that to a bio, non-bio systemic, or new topical is a switch&lt;/LI&gt;
&lt;LI&gt;If a patient is first observed withdrawing a non-bio systemic, any withdrawal of a treatment after that to a bio or a new non-bio systemic is a switch
&lt;UL&gt;
&lt;LI&gt;A withdrawal of any topical is not a switch&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;If a patient is first observed withdrawing a bio, a switch can only be made to another bio (which is different from the first)
&lt;UL&gt;
&lt;LI&gt;A withdrawal of any topical or non-bio systemic is not a switch&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to the logic above, once a patient has switched to a higher class of therapy, the lower classes are considered concomitant medication and a withdrawal of a concomitant medication does not indicate a treatment switch.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In nutshell, If a patient moves from lower class of treatment to upper or withing the same class(different ATC code) then it will consider as a Switch.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Treatment &lt;SPAN data-dobid="hdw"&gt;hierarchy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Biologics&amp;gt; Non_Bio_Sys&amp;gt;Topical&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am adding sample dataset for the reference, with variable information :&lt;/P&gt;
&lt;P&gt;LPNR: unique subjID&lt;/P&gt;
&lt;P&gt;EDATUM: prescrition date ( treatment recieved date)&lt;/P&gt;
&lt;P&gt;ATC_CODE: codes for each of treament type&lt;/P&gt;
&lt;P&gt;'D05AX52' ,&lt;BR /&gt;'D05AX02' = PSorasis(Topical)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;'L01XC02'&amp;nbsp; ,&lt;BR /&gt;'L04AA24',&lt;BR /&gt;'L04AB01',&lt;BR /&gt;'L04AB02',&lt;BR /&gt;'L04AB04',&lt;BR /&gt;'L04AB05',&lt;BR /&gt;'L04AB06',&lt;BR /&gt;'L04AC03',&lt;BR /&gt;'L04AC07' =Non_Bio_systemic&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;'A11CC03'&amp;nbsp; ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;'D05BB02',&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;'L01BA01',&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;'L01BB03' ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;'L01XX05' ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;'L04AA21' ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;'L04AD01' ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;'L04AX03' =Biologics&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TYPE: Treatment type&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be great , if you can help me with SAS code to indentify the Subjects with Switches .&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 15:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269473#M53388</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-05-10T15:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269551#M53431</link>
      <description>&lt;P&gt;Hi mate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I couldn't understand what you mean exactly but i think you are looking for something to check where are these dependencies changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My guess is you can use the LAST. or FIRST. options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME REFFILE "/PATH/sample_data.xlsx" TERMSTR=CR;

PROC IMPORT DATAFILE=REFFILE
	DBMS=XLSX
	OUT=WORK.IMPORT;
	GETNAMES=YES;
RUN;

PROC SORT DATA=IMPORT;
  BY LPNR ATC_CODE TYPE;
RUN;

DATA NEED;
	LENGTH INFO_CHANGE $ 20; 
	SET IMPORT;
	BY LPNR ATC_CODE TYPE;
	IF LAST.LPNR AND LAST.ATC_CODE AND LAST.TYPE THEN INFO_CHANGE = "CHANGED";
	ELSE INFO_CHANGE = "UNCHANGED";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The last data step in this code prints the changed if the dependencies occured in the last time they changed.&lt;/P&gt;
&lt;P&gt;And unchanged for the rest.&lt;BR /&gt;&lt;BR /&gt;If you need the first time jus switch to FIRST. and checkout the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 19:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269551#M53431</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2016-05-10T19:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269627#M53444</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/50353"&gt;@DartRodrigo﻿&lt;/a&gt; Hi , Thanks for the quick reply. I am sorry for the unclear explaination, but what i exactly means is:&lt;/P&gt;
&lt;P&gt;as you see the data, we have three treatment type in TYPE variable. Now for each Type variable we have different ATC_CODEs. I need to identify the event (SWITCH) , whenever subject changes his treatment type from Lower treatment type( i,e Topical) to Higher treatment group(i,e Non_bio_sys or Biologics) during his treatment period. Same is true for Non_sys_Bio , if Subject changes to Biologics, then it will also consider as Switch.&amp;nbsp; Event is also to be counted whenever subjects changes his ATC_CODEs within his treatment TYPE , ie in case, when Treatment TYPE is "Psorasis" and if Its' ATC_CODE changes , then we have to identify it as SWITCH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;same is true for other treatment arm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;order of treatment: BIOLOGICS&amp;gt; NON_BIO_SYS&amp;gt; TOPICAL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope i am able to clear you doubt. please help. thanks&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 04:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269627#M53444</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-05-11T04:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269657#M53452</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;length TYPE $20.;&lt;BR /&gt;input pnr ATC_CODE $ type $ EDATUM $ 10. ;&lt;BR /&gt;date=input(edatum,mmddyy10.);&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;478 L04AX03 Nonbiologic_systemic 2/10/2010 &lt;BR /&gt;478 D05AX52 Psoriasis 2/23/2010 &lt;BR /&gt;478 L04AX03 Nonbiologic_systemic 3/5/2010 &lt;BR /&gt;478 L04AX03 Nonbiologic_systemic 5/18/2010 &lt;BR /&gt;478 L04AX03 Nonbiologic_systemic 8/2/2010 &lt;BR /&gt;478 L04AX03 Nonbiologic_systemic 11/3/2010&lt;BR /&gt;478 L04AX03 Nonbiologic_systemic 2/7/2011 &lt;BR /&gt;478 L04AX03 Nonbiologic_systemic 8/16/2011&lt;BR /&gt;478 L04AX03 Nonbiologic_systemic 11/22/2011&lt;BR /&gt;603 D05AX02 Psoriasis 8/24/2005 &lt;BR /&gt;603 D05AX02 Psoriasis 10/13/2005 &lt;BR /&gt;603 D05AX02 Psoriasis 6/2/2006&lt;BR /&gt;603 D05AX02 Psoriasis 7/19/2006 &lt;BR /&gt;603 D05AX02 Psoriasis 4/3/2007&lt;BR /&gt;603 D05AX02 Psoriasis 12/7/2007 &lt;BR /&gt;603 D05AX02 Psoriasis 1/4/2008&lt;BR /&gt;603 D05AX02 Psoriasis 1/4/2008 &lt;BR /&gt;603 D05AX02 Psoriasis 10/2/2008&lt;BR /&gt;603 D05AX52 Psoriasis 3/16/2009&lt;BR /&gt;603 D05AX52 Psoriasis 3/16/2009&lt;BR /&gt;603 D05AX52 Psoriasis 5/7/2009&lt;BR /&gt;603 D05AX52 Psoriasis 8/21/2009&lt;BR /&gt;603 D05AX52 Psoriasis 11/9/2009 &lt;BR /&gt;603 D05AX52 Psoriasis 3/19/2010 &lt;BR /&gt;603 D05AX52 Psoriasis 7/30/2010 &lt;BR /&gt;603 D05AX52 Psoriasis 7/30/2010&lt;BR /&gt;603 D05AX52 Psoriasis 1/13/2011 &lt;BR /&gt;603 D05AX52 Psoriasis 5/3/2011 &lt;BR /&gt;603 D05AX52 Psoriasis 12/12/2011&lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 1/17/2006&lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 8/23/2006&lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 11/9/2006&lt;BR /&gt;1103 D05AX52 Psoriasis 4/19/2007 &lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 4/19/2007 &lt;BR /&gt;1103 D05AX52 Psoriasis 10/26/2007 &lt;BR /&gt;1103 D05AX52 Psoriasis 4/1/2008&lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 10/20/2008 &lt;BR /&gt;1103 D05AX52 Psoriasis 10/20/2008&lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 4/7/2009 &lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 11/20/2009 &lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 11/12/2010 &lt;BR /&gt;1103 L04AX03 Nonbiologic_systemic 8/12/2011&lt;BR /&gt;1103 D05AX52 Psoriasis 10/22/2011 &lt;BR /&gt;1103 D05AX52 Psoriasis 12/29/2011&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;/*sort the data to keep the date in increase order to know subject moved to other treatment or not*/&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sort data=have;&lt;BR /&gt;by pnr date;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data need;&lt;BR /&gt;set have;&lt;BR /&gt;length change $ 10.;&lt;BR /&gt;by pnr;&lt;BR /&gt;/*create new variable change and keep constant if it is topical for first observation*/&lt;BR /&gt;/*compare topical values with next values if it changes to other non bio or bio then switched*/&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; if first.pnr and atc_code in ( 'D05AX52','D05AX02') then change="";&lt;BR /&gt; else if not first.pnr and atc_code not in('D05AX52','D05AX02','L01XC02','L04AA24','L04AB01','L04AB02','L04AB04','L04AB05','L04AB06','L04AC03','L04AC07','A11CC03','D05BB02','L01BA01','L01BB03' ,'L01XX05' ,'L04AA21' ,'L04AD01' ,'L04AX03')&lt;BR /&gt; then change='switched';&lt;/P&gt;
&lt;P&gt;/*compare non bio values with next values if it changes to other non bio or bio then switched*/&lt;BR /&gt; if first.pnr and atc_code in ('L01XC02','L04AA24','L04AB01','L04AB02','L04AB04','L04AB05','L04AB06','L04AC03','L04AC07') then change="";&lt;BR /&gt; else if not first.pnr and atc_code not in( 'D05AX52','D05AX02') and atc_code in('L01XC02','L04AA24','L04AB01','L04AB02','L04AB04','L04AB05','L04AB06','L04AC03','L04AC07','A11CC03','D05BB02','L01BA01','L01BB03' ,'L01XX05' ,'L04AA21' ,'L04AD01' ,'L04AX03')&lt;BR /&gt; then change='switched';&lt;/P&gt;
&lt;P&gt;/*compare bio with next values if it changes to other bio then switched*/&lt;/P&gt;
&lt;P&gt;if first.pnr and atc_code in('A11CC03','D05BB02','L01BA01','L01BB03' ,'L01XX05' ,'L04AA21' ,'L04AD01' ,'L04AX03') then change='';&lt;BR /&gt; else if not first.pnr and atc_code not in( 'D05AX52','D05AX02') and atc_code in('A11CC03','D05BB02','L01BA01','L01BB03' ,'L01XX05' ,'L04AA21' ,'L04AD01' ,'L04AX03') then change='switched';&lt;BR /&gt; if atc_code=lag(atc_code) then change="";&lt;BR /&gt; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this may help you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 08:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269657#M53452</guid>
      <dc:creator>ramchinna24</dc:creator>
      <dc:date>2016-05-11T08:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269661#M53453</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51397"&gt;@ramchinna24﻿&lt;/a&gt; Hi, Thanks for the logic, but what if ATC code withing the psorasis or within other treatment group changes, we also need to identify those changes as switches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i want this :&lt;/P&gt;
&lt;TABLE width="508"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;lpnr&lt;/TD&gt;
&lt;TD width="72"&gt;ATC_CODE&lt;/TD&gt;
&lt;TD width="145"&gt;TYPE&lt;/TD&gt;
&lt;TD width="75"&gt;EDATUM&lt;/TD&gt;
&lt;TD width="88"&gt;Flag_switch&lt;/TD&gt;
&lt;TD width="64"&gt;Comment&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;478&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;2/10/2010&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;478&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;2/23/2010&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;478&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;3/5/2010&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;This is switch because subject is changing his treatment from lower(psorais) to higher treatment(non_bio_sys/bio)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;478&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;5/18/2010&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;478&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;8/2/2010&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;478&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;11/3/2010&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;478&lt;/TD&gt;
&lt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p;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;603&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;3/16/2009&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;This is switch because subject is changing his ATC code within Psorasis(or any other treatment group)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;603&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;5/7/2009&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;603&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;8/21/2009&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;603&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;11/9/2009&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;603&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;3/19/2010&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;603&l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lt;/TD&gt;
&lt;TD&gt;This is switch because subject is changing his treatment from lower(psorais) to higher treatment(non_bio_sys/bio)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1103&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;10/20/2008&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1103&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;4/7/2009&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;This is switch because subject is changing his treatment from lower(psorais) to higher treatment(non_bio_sys/bio)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1103&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;11/20/2009&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1103&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;11/12/2010&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1103&lt;/TD&gt;
&lt;TD&gt;L04AX03&lt;/TD&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;8/12/2011&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1103&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;10/22/2011&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1103&lt;/TD&gt;
&lt;TD&gt;D05AX52&lt;/TD&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;12/29/2011&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 11 May 2016 08:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269661#M53453</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-05-11T08:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269664#M53454</link>
      <description>&lt;P&gt;even if code changes with in the group, it works. Just try it once. hope it works. If it doesnt work, tell me .&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 08:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269664#M53454</guid>
      <dc:creator>ramchinna24</dc:creator>
      <dc:date>2016-05-11T08:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269666#M53455</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51397"&gt;@ramchinna24﻿&lt;/a&gt; Hi , code is working on treatment Type level, however whenever atc_codes are changing withing the treatment type, it's not working. I have added the desired output in previous reply, please kindly check.&lt;/P&gt;
&lt;P&gt;Many thanks for your's help!!&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 08:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269666#M53455</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-05-11T08:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269667#M53456</link>
      <description>proc sort data=have;&lt;BR /&gt;by pnr atc_code type date;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data need;&lt;BR /&gt;set have;&lt;BR /&gt;length change $ 10.;&lt;BR /&gt;by pnr atc_code;&lt;BR /&gt;/*create new variable change and keep constant if it is topical for first observation*/&lt;BR /&gt;/*compare topical values with next values if it changes to other non bio or bio then switched*/&lt;BR /&gt;&lt;BR /&gt;if first.pnr and atc_code in ( 'D05AX52','D05AX02') then change="";&lt;BR /&gt;else if not first.pnr and atc_code in('D05AX52','D05AX02','L01XC02','L04AA24','L04AB01','L04AB02','L04AB04','L04AB05','L04AB06','L04AC03','L04AC07','A11CC03','D05BB02','L01BA01','L01BB03' ,'L01XX05' ,'L04AA21' ,'L04AD01' ,'L04AX03')&lt;BR /&gt;then change='switched';&lt;BR /&gt;/*compare non bio values with next values if it changes to other non bio or bio then switched*/&lt;BR /&gt;if first.pnr and atc_code in ('L01XC02','L04AA24','L04AB01','L04AB02','L04AB04','L04AB05','L04AB06','L04AC03','L04AC07') then change="";&lt;BR /&gt;else if not first.pnr and atc_code not in( 'D05AX52','D05AX02') and atc_code in('L01XC02','L04AA24','L04AB01','L04AB02','L04AB04','L04AB05','L04AB06','L04AC03','L04AC07','A11CC03','D05BB02','L01BA01','L01BB03' ,'L01XX05' ,'L04AA21' ,'L04AD01' ,'L04AX03')&lt;BR /&gt;then change='switched';&lt;BR /&gt;/*compare bio with next values if it changes to other bio then switched*/&lt;BR /&gt;if first.pnr and atc_code in('A11CC03','D05BB02','L01BA01','L01BB03' ,'L01XX05' ,'L04AA21' ,'L04AD01' ,'L04AX03') then change='';&lt;BR /&gt;else if not first.pnr and atc_code not in( 'D05AX52','D05AX02','L01XC02','L04AA24','L04AB01','L04AB02','L04AB04','L04AB05','L04AB06','L04AC03','L04AC07') and atc_code in('A11CC03','D05BB02','L01BA01','L01BB03' ,'L01XX05' ,'L04AA21' ,'L04AD01' ,'L04AX03') then change='switched';&lt;BR /&gt;if atc_code=lag(atc_code) then change="";&lt;BR /&gt;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 11 May 2016 09:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269667#M53456</guid>
      <dc:creator>ramchinna24</dc:creator>
      <dc:date>2016-05-11T09:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269669#M53458</link>
      <description>Did u try last updated solution? I sent updated code and it works for you&lt;BR /&gt;</description>
      <pubDate>Wed, 11 May 2016 09:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269669#M53458</guid>
      <dc:creator>ramchinna24</dc:creator>
      <dc:date>2016-05-11T09:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269676#M53460</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51397"&gt;@ramchinna24﻿&lt;/a&gt; I think, sorting order is conflicting with data, for example on: PNR 478, Switch was recorded at 5th March 2010 , &lt;/P&gt;
&lt;TABLE width="220"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="145"&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD width="75"&gt;2/10/2010&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Psoriasis&lt;/TD&gt;
&lt;TD&gt;2/23/2010&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Nonbiologic_systemic&lt;/TD&gt;
&lt;TD&gt;3/5/2010&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when we are sorting it on atc_code and then type and followed by edatum , switch is recording at 2/10/2010.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 09:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269676#M53460</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-05-11T09:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269785#M53490</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51397"&gt;@ramchinna24﻿&lt;/a&gt;&amp;nbsp; Hi I have tried this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set new_have;/*sorted on pnr date*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by pnr;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Psoriasis' and type in ('Nonbiologic_systemic' 'Biologics')&amp;nbsp;&amp;nbsp; then f=1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Psoriasis' and type='Psoriasis' and lag(atc_code) ne atc_code then f=1;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Nonbiologic_systemic' and type in ('Biologics') then f=1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Nonbiologic_systemic' and type='Nonbiologic_systemic' and lag(atc_code) ne atc_code then f=1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type) in ('Nonbiologic_systemic' 'Psoriasis') and type='Biologics' then f=1; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(type)='Biologics' and type='Biologics' and lag(atc_code) ne atc_code then f=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;/* &amp;nbsp;&amp;nbsp; &amp;nbsp;if lag(pnr) =pnr and lag(atc_code) ne atc_code then f=1; */&lt;BR /&gt;&lt;BR /&gt;run;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's ignoring the by group and adding flagging&amp;nbsp; for situations when patient by group is changes.&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 16:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269785#M53490</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-05-11T16:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269956#M53548</link>
      <description>&lt;P&gt;proc format;&lt;BR /&gt; value treatType 1 = "Topical"&lt;BR /&gt; 2 = "Non-biologic systemics"&lt;BR /&gt; 3 = "Biologics";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt; format pnr 8. tType treatType. tCode $10. date YYMMDDs8.;&lt;BR /&gt; informat tType 1. date yymmdd10.;&lt;BR /&gt; input pnr tCode tType date;&lt;BR /&gt; datalines;&lt;BR /&gt;478 L04AX03 2 2010-02-10&lt;BR /&gt;478 D05AX52 1 2010-02-23&lt;BR /&gt;478 L04AX03 2 2010-03-05&lt;BR /&gt;478 L04AX03 2 2010-05-18&lt;BR /&gt;478 L04AX03 2 2010-08-02&lt;BR /&gt;478 L04AX03 2 2010-11-03&lt;BR /&gt;478 L04AX03 2 2011-02-07&lt;BR /&gt;478 L04AX03 2 2011-08-16&lt;BR /&gt;478 L04AX03 2 2011-11-22&lt;BR /&gt;603 D05AX02 1 2005-08-24&lt;BR /&gt;603 D05AX02 1 2005-10-13&lt;BR /&gt;603 D05AX02 1 2006-06-02&lt;BR /&gt;603 D05AX02 1 2006-07-19&lt;BR /&gt;603 D05AX02 1 2007-04-03&lt;BR /&gt;603 D05AX02 1 2007-12-07&lt;BR /&gt;603 D05AX02 1 2008-01-04&lt;BR /&gt;603 D05AX02 1 2008-01-04&lt;BR /&gt;603 D05AX02 1 2008-10-02&lt;BR /&gt;603 D05AX52 1 2009-03-16&lt;BR /&gt;603 D05AX52 1 2009-03-16&lt;BR /&gt;603 D05AX52 1 2009-05-07&lt;BR /&gt;603 D05AX52 1 2009-08-21&lt;BR /&gt;603 D05AX52 1 2009-11-09&lt;BR /&gt;603 D05AX52 1 2010-03-19&lt;BR /&gt;603 D05AX52 1 2010-07-30&lt;BR /&gt;603 D05AX52 1 2010-07-30&lt;BR /&gt;603 D05AX52 1 2011-01-13&lt;BR /&gt;603 D05AX52 1 2011-05-03&lt;BR /&gt;603 D05AX52 1 2011-12-12&lt;BR /&gt;1103 L04AX03 2 2006-01-17&lt;BR /&gt;1103 L04AX03 2 2006-08-23&lt;BR /&gt;1103 L04AX03 2 2006-11-09&lt;BR /&gt;1103 D05AX52 1 2007-04-19&lt;BR /&gt;1103 L04AX03 2 2007-04-19&lt;BR /&gt;1103 D05AX52 1 2007-10-26&lt;BR /&gt;1103 D05AX52 1 2008-04-01&lt;BR /&gt;1103 L04AX03 2 2008-10-20&lt;BR /&gt;1103 D05AX52 1 2008-10-20&lt;BR /&gt;1103 L04AX03 2 2009-04-07&lt;BR /&gt;1103 L04AX03 2 2009-11-20&lt;BR /&gt;1103 L04AX03 2 2010-11-12&lt;BR /&gt;1103 L04AX03 2 2011-08-12&lt;BR /&gt;1103 D05AX52 1 2011-10-22&lt;BR /&gt;1103 D05AX52 1 2011-12-29&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=have;&lt;BR /&gt; by pnr date;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt; by pnr;&lt;BR /&gt; format switch 1. tCode_prev $10. tType_prev 3.;&lt;BR /&gt; retain tCode_prev '' tType_prev .;&lt;BR /&gt; format switch 1.;&lt;/P&gt;
&lt;P&gt;if first.pnr then do;&lt;BR /&gt; switch = 0;&lt;BR /&gt; end;&lt;/P&gt;
&lt;P&gt;else if tType_prev = 1 then do;&lt;BR /&gt; if tType &amp;gt; 1 or tCode ne tCode_prev then switch = 1;&lt;BR /&gt; else switch = 0;&lt;BR /&gt; end;&lt;/P&gt;
&lt;P&gt;else if tType_prev = 2 then do;&lt;BR /&gt; if tType &amp;gt; 2 or (tType = 2 and tCode ne tCode_prev) then switch = 1;&lt;BR /&gt; else switch = 0;&lt;BR /&gt; end;&lt;/P&gt;
&lt;P&gt;else if tType_prev = 3 then do;&lt;BR /&gt; /* Here's your homework */&lt;BR /&gt; end;&lt;/P&gt;
&lt;P&gt;output; &lt;BR /&gt; tCode_prev = tCode;&lt;BR /&gt; tType_prev = tType;&lt;/P&gt;
&lt;P&gt;drop tCode_prev tType_prev;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 04:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/269956#M53548</guid>
      <dc:creator>ramchinna24</dc:creator>
      <dc:date>2016-05-12T04:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the number of subjects who had treatment switch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/270654#M53811</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51397"&gt;@ramchinna24﻿&lt;/a&gt; Many Thanks for the help and time! . It worked&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 09:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-number-of-subjects-who-had-treatment-switch/m-p/270654#M53811</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-05-16T09:42:47Z</dc:date>
    </item>
  </channel>
</rss>

