<?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: Count change of values across variables in a row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-change-of-values-across-variables-in-a-row/m-p/775803#M246634</link>
    <description>&lt;P&gt;This works exactly how I wanted it to. Thanks a lot PaigeMiller!&lt;/P&gt;</description>
    <pubDate>Fri, 22 Oct 2021 04:13:33 GMT</pubDate>
    <dc:creator>Recker96</dc:creator>
    <dc:date>2021-10-22T04:13:33Z</dc:date>
    <item>
      <title>Count change of values across variables in a row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-change-of-values-across-variables-in-a-row/m-p/775669#M246576</link>
      <description>&lt;P&gt;Hi SAS wizards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of customers and 24 month columns(mo1, mo2...) in front of each. Each can take values from 1 to n. However this 'n' is unique for each row only. For e.g. for customer A (say n=4), mo1=1, mo2=2, mo3=2, mo4=2, mo5=3, mo6=4 and so on til mo24. I want to count how many times this value changes across the 24 months for each customer (i.e. in this 6 month period in the example, the count would be 3). I understand the logic of doing it but don't how to code it in using macros/data step/loops etc in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic I have is:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Initiate a counter at 0 and a ref as mo1 value.&lt;/LI&gt;&lt;LI&gt;Check this ref vs mo2, mo3 etc sequentially and increase counter when value is different while also updating ref as the new value.&lt;/LI&gt;&lt;LI&gt;Return the Counter value at the end for each row/customer.&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Thu, 21 Oct 2021 15:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-change-of-values-across-variables-in-a-row/m-p/775669#M246576</guid>
      <dc:creator>Recker96</dc:creator>
      <dc:date>2021-10-21T15:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Count change of values across variables in a row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-change-of-values-across-variables-in-a-row/m-p/775673#M246577</link>
      <description>&lt;P&gt;Use an ARRAY in a DATA step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array mo mo1-mo24;
    count=0;
    do i=2 to 24;
         if mo(i)^=mo(i-1) then count=count+1;
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Oct 2021 15:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-change-of-values-across-variables-in-a-row/m-p/775673#M246577</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-21T15:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Count change of values across variables in a row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-change-of-values-across-variables-in-a-row/m-p/775803#M246634</link>
      <description>&lt;P&gt;This works exactly how I wanted it to. Thanks a lot PaigeMiller!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Oct 2021 04:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-change-of-values-across-variables-in-a-row/m-p/775803#M246634</guid>
      <dc:creator>Recker96</dc:creator>
      <dc:date>2021-10-22T04:13:33Z</dc:date>
    </item>
  </channel>
</rss>

