<?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 Create a count variable per ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-count-variable-per-ID/m-p/915728#M360793</link>
    <description>&lt;P&gt;This is the dataset we have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input ID age;
datalines;
1	131
1	0
1	0
2	22
2	76
3	0&lt;BR /&gt;
3	48
3	48
3	3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do you create a variable that counts how many times the variable "age" has appeared up until that age. This means that the same ID can have multiple ages. The output should look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
input ID count_events;
datalines;
a1	131	1
a1	0	2
a1	0	3
b2	22	1
b2	76	2
c4	0	1
c4	48	2
c4	48	3
c4	3	4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 12 Feb 2024 23:28:04 GMT</pubDate>
    <dc:creator>ANKH1</dc:creator>
    <dc:date>2024-02-12T23:28:04Z</dc:date>
    <item>
      <title>Create a count variable per ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-count-variable-per-ID/m-p/915728#M360793</link>
      <description>&lt;P&gt;This is the dataset we have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input ID age;
datalines;
1	131
1	0
1	0
2	22
2	76
3	0&lt;BR /&gt;
3	48
3	48
3	3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do you create a variable that counts how many times the variable "age" has appeared up until that age. This means that the same ID can have multiple ages. The output should look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
input ID count_events;
datalines;
a1	131	1
a1	0	2
a1	0	3
b2	22	1
b2	76	2
c4	0	1
c4	48	2
c4	48	3
c4	3	4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Feb 2024 23:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-count-variable-per-ID/m-p/915728#M360793</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2024-02-12T23:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a count variable per ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-count-variable-per-ID/m-p/915730#M360794</link>
      <description>&lt;P&gt;That looks like a basic counter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by ID;
if first.id then count_events=0;
count_events+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note your want data set does not match the have and is missing a variable. Please ensure you test the code you post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is the dataset we have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input ID age;
datalines;
1	131
1	0
1	0
2	22
2	76
3	0&lt;BR /&gt;
3	48
3	48
3	3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How do you create a variable that counts how many times the variable "age" has appeared up until that age. This means that the same ID can have multiple ages. The output should look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data want;
input ID count_events;
datalines;
a1	131	1
a1	0	2
a1	0	3
b2	22	1
b2	76	2
c4	0	1
c4	48	2
c4	48	3
c4	3	4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 23:35:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-count-variable-per-ID/m-p/915730#M360794</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-12T23:35:50Z</dc:date>
    </item>
  </channel>
</rss>

