<?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 Count changes in column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column/m-p/748637#M235124</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I would like to mark value changes in a column like below:&lt;/P&gt;
&lt;TABLE border="1" width="98.12164721216608%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;ID&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;VALUE&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;CHANGE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;12&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;12&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;1&lt;/TD&gt;
&lt;TD height="30px"&gt;15&lt;/TD&gt;
&lt;TD height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;In this example ID and VALUE is my data and I want to make CHANGE column equal 1 each time the value change in given ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried this code but it aplies 0 each row. Maybe&amp;nbsp;lag function could be helpful but I'm not sure how to use it&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id value notsorted;&lt;BR /&gt;count=first.value;&lt;BR /&gt;if first.id then count=0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me with solution?&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jun 2021 09:19:22 GMT</pubDate>
    <dc:creator>PatrykSAS</dc:creator>
    <dc:date>2021-06-17T09:19:22Z</dc:date>
    <item>
      <title>Count changes in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column/m-p/748637#M235124</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I would like to mark value changes in a column like below:&lt;/P&gt;
&lt;TABLE border="1" width="98.12164721216608%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;ID&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;VALUE&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;CHANGE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;12&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;12&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;1&lt;/TD&gt;
&lt;TD height="30px"&gt;15&lt;/TD&gt;
&lt;TD height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;In this example ID and VALUE is my data and I want to make CHANGE column equal 1 each time the value change in given ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried this code but it aplies 0 each row. Maybe&amp;nbsp;lag function could be helpful but I'm not sure how to use it&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id value notsorted;&lt;BR /&gt;count=first.value;&lt;BR /&gt;if first.id then count=0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me with solution?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 09:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column/m-p/748637#M235124</guid>
      <dc:creator>PatrykSAS</dc:creator>
      <dc:date>2021-06-17T09:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count changes in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column/m-p/748640#M235127</link>
      <description>&lt;PRE&gt;ID	VALUE	change
1	10	0
1	10	0
1	12	1
1	12	0
1	15	1
&lt;/PRE&gt;
&lt;P&gt;Works for me:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID VALUE;
datalines;
1 10
1 10
1 12
1 12
1 15
;

data want;
set have;
by id value notsorted;
change = first.value;
if first.id then change = 0;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;ID	VALUE	change
1	10	0
1	10	0
1	12	1
1	12	0
1	15	1
&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jun 2021 09:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column/m-p/748640#M235127</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-17T09:35:52Z</dc:date>
    </item>
  </channel>
</rss>

