<?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 recode a variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72165#M20902</link>
    <description>Look up BY Group processing and retain. &lt;BR /&gt;
&lt;BR /&gt;
The following will work&lt;BR /&gt;
data have;&lt;BR /&gt;
input id;&lt;BR /&gt;
cards;&lt;BR /&gt;
3&lt;BR /&gt;
3&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
6&lt;BR /&gt;
7&lt;BR /&gt;
7&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=have;&lt;BR /&gt;
by id;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
	set have;&lt;BR /&gt;
	by id;&lt;BR /&gt;
	retain id2 0;&lt;BR /&gt;
	if first.id then id2+1;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 14 Sep 2010 22:37:28 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2010-09-14T22:37:28Z</dc:date>
    <item>
      <title>how to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72164#M20901</link>
      <description>Hello all-&lt;BR /&gt;
&lt;BR /&gt;
suppose in my data set i have an id variable:&lt;BR /&gt;
&lt;BR /&gt;
id&lt;BR /&gt;
3&lt;BR /&gt;
3&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
6&lt;BR /&gt;
7&lt;BR /&gt;
7&lt;BR /&gt;
&lt;BR /&gt;
and i want to create a new id variable (in the same data set) say id2 such that now we have in the data set:&lt;BR /&gt;
&lt;BR /&gt;
id id2&lt;BR /&gt;
3  1&lt;BR /&gt;
3  1&lt;BR /&gt;
3  1&lt;BR /&gt;
4  2&lt;BR /&gt;
4  2&lt;BR /&gt;
4  2&lt;BR /&gt;
4  2&lt;BR /&gt;
6  3&lt;BR /&gt;
7  4&lt;BR /&gt;
7  4&lt;BR /&gt;
&lt;BR /&gt;
and so on. i need to be able to generalize this regardless of the numbers in the id column. in short i need to recode the id column starting from 1 on up.&lt;BR /&gt;
&lt;BR /&gt;
Any way to do this?&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Geo</description>
      <pubDate>Tue, 14 Sep 2010 22:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72164#M20901</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-14T22:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72165#M20902</link>
      <description>Look up BY Group processing and retain. &lt;BR /&gt;
&lt;BR /&gt;
The following will work&lt;BR /&gt;
data have;&lt;BR /&gt;
input id;&lt;BR /&gt;
cards;&lt;BR /&gt;
3&lt;BR /&gt;
3&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
4&lt;BR /&gt;
6&lt;BR /&gt;
7&lt;BR /&gt;
7&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=have;&lt;BR /&gt;
by id;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
	set have;&lt;BR /&gt;
	by id;&lt;BR /&gt;
	retain id2 0;&lt;BR /&gt;
	if first.id then id2+1;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 14 Sep 2010 22:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72165#M20902</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2010-09-14T22:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72166#M20903</link>
      <description>Thanks!!</description>
      <pubDate>Wed, 15 Sep 2010 03:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72166#M20903</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-15T03:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72167#M20904</link>
      <description>Just a minor reminder that the "accumulator" variable in the sum statement is automatically initialized to zero and retained. Thus the retain statement is not necessary. The fine manual even metions that a sum statement is equivalent to:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  retain variable 0;&lt;BR /&gt;
  varibale = sum(varible, expression);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Thus your data want step can be as simple as:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  data want;&lt;BR /&gt;
    set have;&lt;BR /&gt;
    by id;&lt;BR /&gt;
    id2 + first.id;&lt;BR /&gt;
  run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 15 Sep 2010 14:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-recode-a-variable/m-p/72167#M20904</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-09-15T14:22:27Z</dc:date>
    </item>
  </channel>
</rss>

