<?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: Create ID variable for repeated rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345373#M79454</link>
    <description>&lt;P&gt;Thanks for the effective solution.&lt;BR /&gt;I have another question, maybe you can help as well.&lt;/P&gt;&lt;P&gt;Some of the filenumbers are repeated (because they belong to the same patient) but they come from different admissions to the hospital (it is seen from the other variables). Can I get an ID for admission and not patient. I'm thinking I can use a newly recorded measure in another variable as well in the code that you sent me to identify a new entry (i.e. admission).&lt;BR /&gt;ex.&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; m1 &amp;nbsp; NEW_ID1&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID1&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID1&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; m2 &amp;nbsp; NEW_ID2&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID2&lt;BR /&gt;file29898998 ID2 2 &amp;nbsp; m1 &amp;nbsp; NEW_ID3&lt;BR /&gt;file29898998 ID2 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID3&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; m1 &amp;nbsp; NEW_ID4&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID4&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID4&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; m2 &amp;nbsp; NEW_ID5&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID5&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 29 Mar 2017 13:55:49 GMT</pubDate>
    <dc:creator>seltonsy</dc:creator>
    <dc:date>2017-03-29T13:55:49Z</dc:date>
    <item>
      <title>Create ID variable for repeated rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345172#M79382</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to create a new variable (ID, an numerical variable from 1 to x) from a dataset that has repeated rows per medical file number. The medical file numbers are not consequent, I'd like to create a new variable with consequent ID nos for every medical file number. I show below an example, I want to create the last column (1,2,3.....)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file1867678 &amp;nbsp;ID1 &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file1867678 &amp;nbsp;&lt;/SPAN&gt;ID1 &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file1867678 &amp;nbsp;&lt;/SPAN&gt;ID1 &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;file29898998 &amp;nbsp;ID2 &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file29898998 &amp;nbsp;&lt;/SPAN&gt;ID2 &amp;nbsp;2&lt;/P&gt;&lt;P&gt;file34343333 &amp;nbsp;ID3 &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file34343333 &amp;nbsp;&lt;/SPAN&gt;ID3 &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file34343333 &amp;nbsp;&lt;/SPAN&gt;ID3 &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 20:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345172#M79382</guid>
      <dc:creator>seltonsy</dc:creator>
      <dc:date>2017-03-28T20:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create ID variable for repeated rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345175#M79383</link>
      <description>&lt;P&gt;As long as all same id records are adjacent to each other:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  by filenum notsorted;
  if first.filenum then id+1;
run
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 21:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345175#M79383</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-28T21:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create ID variable for repeated rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345373#M79454</link>
      <description>&lt;P&gt;Thanks for the effective solution.&lt;BR /&gt;I have another question, maybe you can help as well.&lt;/P&gt;&lt;P&gt;Some of the filenumbers are repeated (because they belong to the same patient) but they come from different admissions to the hospital (it is seen from the other variables). Can I get an ID for admission and not patient. I'm thinking I can use a newly recorded measure in another variable as well in the code that you sent me to identify a new entry (i.e. admission).&lt;BR /&gt;ex.&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; m1 &amp;nbsp; NEW_ID1&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID1&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID1&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; m2 &amp;nbsp; NEW_ID2&lt;BR /&gt;file1867678 ID1 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID2&lt;BR /&gt;file29898998 ID2 2 &amp;nbsp; m1 &amp;nbsp; NEW_ID3&lt;BR /&gt;file29898998 ID2 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID3&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; m1 &amp;nbsp; NEW_ID4&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID4&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID4&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; m2 &amp;nbsp; NEW_ID5&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID5&lt;BR /&gt;file34343333 ID3 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_ID5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 13:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345373#M79454</guid>
      <dc:creator>seltonsy</dc:creator>
      <dc:date>2017-03-29T13:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Create ID variable for repeated rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345379#M79456</link>
      <description>&lt;P&gt;You didn't say what your variables were called, so I called the one with the m1 m2 values .. adm&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following does what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  by filenum adm notsorted;
  if first.adm and not missing(adm) then new_id+1;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 14:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ID-variable-for-repeated-rows/m-p/345379#M79456</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-29T14:09:55Z</dc:date>
    </item>
  </channel>
</rss>

