<?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: creating a group variable based on a sequence of numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-a-group-variable-based-on-a-sequence-of-numbers/m-p/818226#M322976</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	x=dif(var);
	retain counter 1;

	if x &amp;gt; 1 then
		counter+1;
	letter_group=byte(64+counter);
	keep var letter_group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;about letters though.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jun 2022 22:40:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-06-14T22:40:29Z</dc:date>
    <item>
      <title>creating a group variable based on a sequence of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-group-variable-based-on-a-sequence-of-numbers/m-p/818221#M322974</link>
      <description>&lt;P&gt;Hi, I would like to create a group variable where the value changes (ie a new group value is created) when there is a gap in the sequence of numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;  
	input var;
cards;
112
114
115
116
117
118
119
120
121
122
183
184
185
186
187
188
189
200
201
202

;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rommel_0-1655244920097.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72289iF27EE814458621F6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rommel_0-1655244920097.png" alt="rommel_0-1655244920097.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 22:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-group-variable-based-on-a-sequence-of-numbers/m-p/818221#M322974</guid>
      <dc:creator>dataMart87</dc:creator>
      <dc:date>2022-06-14T22:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: creating a group variable based on a sequence of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-group-variable-based-on-a-sequence-of-numbers/m-p/818225#M322975</link>
      <description>&lt;P&gt;Is there some mad reason you want that "group variable" to be character? It is much easier with a numeric value.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   retain group 1;
   dvar = dif(var);
   if dvar &amp;gt; 1 then group+1;
   drop dvar;
run;&lt;/PRE&gt;
&lt;P&gt;Retain will keep the value of a variable across the data step boundary.&lt;/P&gt;
&lt;P&gt;The Dif function returns the value of current value-previous value if used carefully.&lt;/P&gt;
&lt;P&gt;Incrementing numbers with +1 is just plain easier than dealing with characters. What value would you want after Z? Plus if the data is "large" you may not make your character variable long enough to hold all the needed characters.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 22:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-group-variable-based-on-a-sequence-of-numbers/m-p/818225#M322975</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-14T22:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: creating a group variable based on a sequence of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-group-variable-based-on-a-sequence-of-numbers/m-p/818226#M322976</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	x=dif(var);
	retain counter 1;

	if x &amp;gt; 1 then
		counter+1;
	letter_group=byte(64+counter);
	keep var letter_group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;about letters though.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 22:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-group-variable-based-on-a-sequence-of-numbers/m-p/818226#M322976</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-14T22:40:29Z</dc:date>
    </item>
  </channel>
</rss>

