<?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: data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562059#M157418</link>
    <description>&lt;P&gt;Numeration by groups is pretty trivial, see the tutorial here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then use the Zd format to add leading zero's and CATX() to combine the data.&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 ODN;

*resets counter at the first of each group;

if first.OD then count=0;
count+1;

new_ID = catx('-', ODN, put(count, z3.));

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181538"&gt;@mauri0623&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable called ODN. The values of&amp;nbsp;ODNs are number such as 101621. If ODN=101621 is happening&amp;nbsp;n times then I need to add a suffix with two values (numeric) - e.g. 10621-01, 10621-02, 10621-03, 10621-04, 10621-05,......10621-n. How can I construct this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 May 2019 19:15:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-05-28T19:15:29Z</dc:date>
    <item>
      <title>Add a counter to repeated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562047#M157408</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable called ODN. The values of&amp;nbsp;ODNs are number such as 101621. If ODN=101621 is happening&amp;nbsp;n times then I need to add a suffix with two values (numeric) - e.g. 10621-01, 10621-02, 10621-03, 10621-04, 10621-05,......10621-n. How can I construct this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 19:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562047#M157408</guid>
      <dc:creator>mauri0623</dc:creator>
      <dc:date>2019-05-28T19:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562051#M157411</link>
      <description>&lt;P&gt;Here, I assume that your values are grouped&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ODN $;
datalines;
101621
101621
101621
101623
101623
101623
101622
101622
;

data want(drop=n);
   length ODN $20;
   do n=1 by 1 until (last.ODN);
      set have;
      by ODN notsorted;
      ODN=cats(ODN, '-', put(n, z2.));
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 May 2019 18:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562051#M157411</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-28T18:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562059#M157418</link>
      <description>&lt;P&gt;Numeration by groups is pretty trivial, see the tutorial here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then use the Zd format to add leading zero's and CATX() to combine the data.&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 ODN;

*resets counter at the first of each group;

if first.OD then count=0;
count+1;

new_ID = catx('-', ODN, put(count, z3.));

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181538"&gt;@mauri0623&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable called ODN. The values of&amp;nbsp;ODNs are number such as 101621. If ODN=101621 is happening&amp;nbsp;n times then I need to add a suffix with two values (numeric) - e.g. 10621-01, 10621-02, 10621-03, 10621-04, 10621-05,......10621-n. How can I construct this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 19:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562059#M157418</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-28T19:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Add a counter to repeated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562060#M157419</link>
      <description>FYI - I updated your title to make it more descriptive. This makes it easier for future users to search in the future and find relevant questions and answers. Also, when you post a question, you'll see a 'Related Topics' on the left hand side of the page. In this case several would be exactly what you needed here.</description>
      <pubDate>Tue, 28 May 2019 19:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562060#M157419</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-28T19:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562962#M157773</link>
      <description>&lt;P&gt;Thank you! I accepted as a solution.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 18:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-counter-to-repeated-values/m-p/562962#M157773</guid>
      <dc:creator>mauri0623</dc:creator>
      <dc:date>2019-05-31T18:55:07Z</dc:date>
    </item>
  </channel>
</rss>

