<?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: Add a label column based on value difference in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463049#M117909</link>
    <description>&lt;P&gt;Post your sample as data step with an expected output sample and not as pics&lt;/P&gt;</description>
    <pubDate>Thu, 17 May 2018 16:27:45 GMT</pubDate>
    <dc:creator>MarkWik</dc:creator>
    <dc:date>2018-05-17T16:27:45Z</dc:date>
    <item>
      <title>Add a label column based on value difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463046#M117908</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset called test_1, I would like to add a column named 'Group' such that 'Group' will be numbers from 1, 2, 3, ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test_1.PNG" style="width: 333px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20595iE01622508CF64C8D/image-size/large?v=v2&amp;amp;px=999" role="button" title="test_1.PNG" alt="test_1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic is: New column 'Group' is&amp;nbsp;within each 'Class' and 'DY_TYP',&lt;/P&gt;&lt;P&gt;Start from&amp;nbsp;row 1, 'Group' = 1, if the difference for 'Price' column greater than 4, ''Group' add 1. ( row&amp;nbsp; 2 - row 1 &amp;gt; 4, then on row 2, 'Group' = 2); otherwise 'Group' keeps the same. Same logic happens to row 3 and row 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since the first 4 rows are in a group ('Class' = PC1 and 'DY_TYP'&amp;nbsp; = WD), It ends.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example, we have 'Group' = 1, 2, 2, 3 for the first 4 rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And row 5 is 'PC2' for 'Class' column, we will start again from 'Group' = 1, and do the same thing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to make this happen in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 16:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463046#M117908</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2018-05-17T16:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Add a label column based on value difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463049#M117909</link>
      <description>&lt;P&gt;Post your sample as data step with an expected output sample and not as pics&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 16:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463049#M117909</guid>
      <dc:creator>MarkWik</dc:creator>
      <dc:date>2018-05-17T16:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Add a label column based on value difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463050#M117910</link>
      <description>&lt;P&gt;Assuming your data set is grouped by CLASS DY_TYP:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by class dy_typ notsorted;&lt;/P&gt;
&lt;P&gt;increase = dif(price);&lt;/P&gt;
&lt;P&gt;if first.dy_typ then group = 1;&lt;/P&gt;
&lt;P&gt;else if increase &amp;gt; 4 then group + 1;&lt;/P&gt;
&lt;P&gt;drop increase;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 16:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463050#M117910</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-17T16:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: Add a label column based on value difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463053#M117911</link>
      <description>&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This tutorial walks through how to add the numeration values using BY group processing.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 16:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463053#M117911</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-17T16:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add a label column based on value difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463055#M117912</link>
      <description>&lt;P&gt;I assumed you're programming here and not using DataFlux or DI Studio (since you posted in the Data Management forum). I moved the post to the Base Programming forum, which is more appropriate. If you're using DI Studio the approach would be different.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 16:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463055#M117912</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-17T16:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Add a label column based on value difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463073#M117918</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;I am not using DI Studio, but EG. Please move it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 17:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463073#M117918</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2018-05-17T17:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add a label column based on value difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463074#M117919</link>
      <description>&lt;P&gt;That works. Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 17:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-label-column-based-on-value-difference/m-p/463074#M117919</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2018-05-17T17:45:45Z</dc:date>
    </item>
  </channel>
</rss>

