<?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: how to create new group/type variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253734#M56907</link>
    <description>&lt;P&gt;Here you go, do not for future posts, put test data in the form of a datastep, as given below:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id price;
datalines;
1 1000
1 1000
1 2000
2 1000
2 1000
3 5000
3 5000
3 7000
;
run;

data want;
  set have;
  by id price;
  retain coll;
  if first.id then coll=1;
  else if first.price then coll=coll+1;
run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Mar 2016 10:23:55 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-03-02T10:23:55Z</dc:date>
    <item>
      <title>how to create new group/type variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253732#M56906</link>
      <description>&lt;P&gt;I want to create the new group/type variable. I have variables&amp;nbsp;ID and PRICE and want to create the variable COLL.&lt;/P&gt;&lt;P&gt;So for each ID i want the type variable COLL, to check whether&amp;nbsp;the price is still the same. So my final table will be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2136iB200BD58EDBF25A8/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="obrazok.png" title="obrazok.png" /&gt;&lt;/P&gt;&lt;P&gt;How can I do it in proc data or proc sql?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 10:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253732#M56906</guid>
      <dc:creator>vonsel</dc:creator>
      <dc:date>2016-03-02T10:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to create new group/type variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253734#M56907</link>
      <description>&lt;P&gt;Here you go, do not for future posts, put test data in the form of a datastep, as given below:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id price;
datalines;
1 1000
1 1000
1 2000
2 1000
2 1000
3 5000
3 5000
3 7000
;
run;

data want;
  set have;
  by id price;
  retain coll;
  if first.id then coll=1;
  else if first.price then coll=coll+1;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Mar 2016 10:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253734#M56907</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-02T10:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to create new group/type variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253740#M56908</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/75792"&gt;@vonsel﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If prices can change in both directions (as is the case for ID 3 in your sample data), you need to add the NOTSORTED&amp;nbsp;option to the BY statement:&amp;nbsp;&lt;FONT face="courier new,courier"&gt;by id price notsorted;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Here's a minor variant of RW9's solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by id price notsorted;
coll+first.price;
if first.id then coll=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Obviously, the numbering in COLL depends on the sort order of the observations. So, I hope you have an additional variable in your real data which determines the sort order within each ID (or you have good reason to believe that the existing sort order is correct).&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 10:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253740#M56908</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-02T10:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to create new group/type variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253755#M56909</link>
      <description>&lt;P&gt;Thanks a lot, both solutions work.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 11:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-create-new-group-type-variable/m-p/253755#M56909</guid>
      <dc:creator>vonsel</dc:creator>
      <dc:date>2016-03-02T11:36:01Z</dc:date>
    </item>
  </channel>
</rss>

