<?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: Create an indicator conditional on change of values within subjects in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/650211#M194994</link>
    <description>&lt;P&gt;The following books are very useful and helped me along the&amp;nbsp;way in my SAS journey so far-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Learning SAS&lt;SUP&gt;®&lt;/SUP&gt;&amp;nbsp;by Example: A Programmer's Guide, Second Edition- &lt;EM&gt;By Ron Cody&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;Practical and Efficient SAS Programming: The Insider's Guide&amp;nbsp;Book by &lt;EM&gt;Martha Messine&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;Data Management Solutions Using SAS®&amp;nbsp;Hash Table Operations: A Business Intelligence Case Study-&lt;SPAN style="color: inherit; font-family: inherit; font-size: 20px;"&gt;By&amp;nbsp;&lt;EM&gt;&lt;A href="https://support.sas.com/en/books/authors/paul-dorfman.html" target="_blank"&gt;Paul Dorfman&lt;/A&gt;&amp;nbsp;&lt;/EM&gt;and&amp;nbsp;&lt;EM&gt;&lt;A href="https://support.sas.com/en/books/authors/don-henderson.html" target="_blank"&gt;Don Henderson&lt;/A&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;SPAN style="color: inherit; font-family: inherit; font-size: 20px;"&gt;That's immense!!!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 May 2020 19:28:08 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-05-24T19:28:08Z</dc:date>
    <item>
      <title>Create an indicator conditional on change of values within subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/649399#M194682</link>
      <description>&lt;P&gt;Hi SAS programmers,&lt;/P&gt;&lt;P&gt;Could you please help me with this problem? I don't even know where to start learning how to do this and not sure whether it is possible.&lt;/P&gt;&lt;P&gt;This is the data:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; data a;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; input id time therapy;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; cards;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 1 0&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 2 0&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 3 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 4 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 1 2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 2 2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 3 2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 4 0&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 1 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 2 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 3 0&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 4 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 1 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; 2 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 3 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 4 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a time-independent indicator variable that takes the value of 1 if subject's therapy became 0 after being 1, or 2; and 0 otherwise. So, suppose therapy=0 means no therapy, while therapies 1 and 2 are types of therapy. If 0 precedes 1 or 2, it is considered it to be normal, while if it follows 1 or 2, it means discontinuation of therapy, which required attention. I ultimately need to know how many people discontinued therapy. Is it at all possible to do in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 23:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/649399#M194682</guid>
      <dc:creator>Dinurik</dc:creator>
      <dc:date>2020-05-20T23:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create an indicator conditional on change of values within subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/649401#M194683</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267481"&gt;@Dinurik&lt;/a&gt;&amp;nbsp; Can you please post your expected output for the input sample you posted. This can help avoid readers in assuming things that may be inaccurate. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 23:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/649401#M194683</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-20T23:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create an indicator conditional on change of values within subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/649403#M194685</link>
      <description>&lt;P&gt;Yes, sorry I haven't done that. Here is the print out of the dataset i need. Discont is the new variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;&amp;nbsp; id&amp;nbsp; &amp;nbsp; time&amp;nbsp; therapy discont &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&g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t;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 20 May 2020 23:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/649403#M194685</guid>
      <dc:creator>Dinurik</dc:creator>
      <dc:date>2020-05-20T23:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create an indicator conditional on change of values within subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/649407#M194688</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267481"&gt;@Dinurik&lt;/a&gt;&amp;nbsp; Thank you. Please try -&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

 data a;
    input id time therapy;
    cards;
        1 1 0
        1 2 0
        1 3 1
        1 4 1
        2 1 2
        2 2 2
        2 3 2
        2 4 0
        3 1 1
        3 2 1
        3 3 0
        3 4 1
        4 1 1
        4  2 1
        4 3 1
        4 4 1
        ;
    run;


data discontinued_therapy;
 do _n_=1 by 1 until(last.id);
  set a;
  by id;
  if not therapy and not first.id and lag(therapy) then discont=1;
 end;
 do _n_=1 to _n_;
  set a;
  discont=^^discont;
  output;
 end;
run;




&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 23:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/649407#M194688</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-20T23:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create an indicator conditional on change of values within subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/650196#M194985</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much! I wrote my one extremely inefficient code involving&amp;nbsp; proc expand to compute the lagged therapy, and creating too many intermediate variables. It was so long and ugly that I didn't dare to share it. Thank you for this short and elegant beauty! Could you please refer me to any education materials where I could educate myself on this kind of programming in SAS?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Sun, 24 May 2020 16:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/650196#M194985</guid>
      <dc:creator>Dinurik</dc:creator>
      <dc:date>2020-05-24T16:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create an indicator conditional on change of values within subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/650211#M194994</link>
      <description>&lt;P&gt;The following books are very useful and helped me along the&amp;nbsp;way in my SAS journey so far-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Learning SAS&lt;SUP&gt;®&lt;/SUP&gt;&amp;nbsp;by Example: A Programmer's Guide, Second Edition- &lt;EM&gt;By Ron Cody&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;Practical and Efficient SAS Programming: The Insider's Guide&amp;nbsp;Book by &lt;EM&gt;Martha Messine&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;Data Management Solutions Using SAS®&amp;nbsp;Hash Table Operations: A Business Intelligence Case Study-&lt;SPAN style="color: inherit; font-family: inherit; font-size: 20px;"&gt;By&amp;nbsp;&lt;EM&gt;&lt;A href="https://support.sas.com/en/books/authors/paul-dorfman.html" target="_blank"&gt;Paul Dorfman&lt;/A&gt;&amp;nbsp;&lt;/EM&gt;and&amp;nbsp;&lt;EM&gt;&lt;A href="https://support.sas.com/en/books/authors/don-henderson.html" target="_blank"&gt;Don Henderson&lt;/A&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;SPAN style="color: inherit; font-family: inherit; font-size: 20px;"&gt;That's immense!!!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 May 2020 19:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/650211#M194994</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-24T19:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create an indicator conditional on change of values within subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/650214#M194996</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 May 2020 19:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-indicator-conditional-on-change-of-values-within/m-p/650214#M194996</guid>
      <dc:creator>Dinurik</dc:creator>
      <dc:date>2020-05-24T19:53:00Z</dc:date>
    </item>
  </channel>
</rss>

