<?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: Creating number ID in sequential order in a column in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629130#M20718</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Using SAS 9.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have many records and I am trying to give each record a number starting with 835 and counting up by 1 from there (836, 837, etc.). I have run the following the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data = controls_merged_back;&lt;BR /&gt;by ID;&lt;BR /&gt;run;&lt;BR /&gt;data step12;&lt;BR /&gt;set controls_merged_back;&lt;BR /&gt;keep record_id group match_key_final match_key_new2 ID Sex dob side scope_date scope_md Date_of_TKA tka_md obs4;&lt;BR /&gt;by ID;&lt;BR /&gt;if first.ID then record_id = 835;&lt;BR /&gt;mrn +1;&lt;BR /&gt;if last.ID then output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ID variable I have is unique to each so if my thought was to start with the first ID = to&amp;nbsp; 835 and count by 1 from there. However, when I run this code it produces 835 in each record, so I obviously did something wrong. If anyone has any suggestions that would be great. Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are not incrementing RECORD_ID anywhere. So it's always 835.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step12;
    set controls_merged_back;
    by ID;
    if _n_=1 then record_id = 834;
    if last.ID then do;
        record_id+1;
        output;
    end;
    keep record_id group match_key_final match_key_new2 ID Sex dob side 
        scope_date scope_md Date_of_TKA tka_md obs4;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Mar 2020 14:47:52 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-03-03T14:47:52Z</dc:date>
    <item>
      <title>Creating number ID in sequential order in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629127#M20716</link>
      <description>&lt;P&gt;Using SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have many records and I am trying to give each record a number starting with 835 and counting up by 1 from there (836, 837, etc.). I have run the following the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data = controls_merged_back;&lt;BR /&gt;by ID;&lt;BR /&gt;run;&lt;BR /&gt;data step12;&lt;BR /&gt;set controls_merged_back;&lt;BR /&gt;keep record_id group match_key_final match_key_new2 ID Sex dob side scope_date scope_md Date_of_TKA tka_md obs4;&lt;BR /&gt;by ID;&lt;BR /&gt;if first.ID then record_id = 835;&lt;BR /&gt;mrn +1;&lt;BR /&gt;if last.ID then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ID variable I have is unique to each so if my thought was to start with the first ID = to&amp;nbsp; 835 and count by 1 from there. However, when I run this code it produces 835 in each record, so I obviously did something wrong. If anyone has any suggestions that would be great. Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 14:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629127#M20716</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-03-03T14:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating number ID in sequential order in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629130#M20718</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Using SAS 9.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have many records and I am trying to give each record a number starting with 835 and counting up by 1 from there (836, 837, etc.). I have run the following the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data = controls_merged_back;&lt;BR /&gt;by ID;&lt;BR /&gt;run;&lt;BR /&gt;data step12;&lt;BR /&gt;set controls_merged_back;&lt;BR /&gt;keep record_id group match_key_final match_key_new2 ID Sex dob side scope_date scope_md Date_of_TKA tka_md obs4;&lt;BR /&gt;by ID;&lt;BR /&gt;if first.ID then record_id = 835;&lt;BR /&gt;mrn +1;&lt;BR /&gt;if last.ID then output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ID variable I have is unique to each so if my thought was to start with the first ID = to&amp;nbsp; 835 and count by 1 from there. However, when I run this code it produces 835 in each record, so I obviously did something wrong. If anyone has any suggestions that would be great. Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are not incrementing RECORD_ID anywhere. So it's always 835.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step12;
    set controls_merged_back;
    by ID;
    if _n_=1 then record_id = 834;
    if last.ID then do;
        record_id+1;
        output;
    end;
    keep record_id group match_key_final match_key_new2 ID Sex dob side 
        scope_date scope_md Date_of_TKA tka_md obs4;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Mar 2020 14:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629130#M20718</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-03T14:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating number ID in sequential order in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629133#M20719</link>
      <description>&lt;P&gt;That code produces 835 in the first record and 1 in the remaining records. Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 14:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629133#M20719</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-03-03T14:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating number ID in sequential order in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629169#M20721</link>
      <description>&lt;P&gt;That happens because your original data set already contains RECORD_ID with a value of 0 on every observation.&amp;nbsp; The existing values of 0 throw off the calculations.&amp;nbsp; You can get rid of it at the last possible moment, in simplified form:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step12;
    set controls_merged_back (drop=record_id);
    by ID;
    retain record_id 834;
    if first.ID then record_id + 1;
    keep record_id group match_key_final match_key_new2 ID Sex dob side 
        scope_date scope_md Date_of_TKA tka_md obs4;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Mar 2020 16:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-number-ID-in-sequential-order-in-a-column/m-p/629169#M20721</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-03-03T16:18:39Z</dc:date>
    </item>
  </channel>
</rss>

