<?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 can I increment my ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648547#M194305</link>
    <description>Ok, I need the max ID instead of 10000.</description>
    <pubDate>Mon, 18 May 2020 13:35:14 GMT</pubDate>
    <dc:creator>SaschaD</dc:creator>
    <dc:date>2020-05-18T13:35:14Z</dc:date>
    <item>
      <title>How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648540#M194299</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to add an Id to my table, it works if I start with 1, but how can I increment new line to this table.&lt;/P&gt;&lt;P&gt;It is necessary to keep the old Ids.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA work.BSP_2;

    SET work.BSP;

    RETAIN _ID;

    IF Index ~= . THEN _ID = Index;

    ELSE DO;
        _ID+1;
    END;

    DROP ID;

    RENAME _ID = ID;

RUN;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sascha&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 13:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648540#M194299</guid>
      <dc:creator>SaschaD</dc:creator>
      <dc:date>2020-05-18T13:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648541#M194300</link>
      <description>&lt;P&gt;Explain further. Show us a portion of the input data. Show us the desired output.&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 13:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648541#M194300</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-18T13:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648542#M194301</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282805"&gt;@SaschaD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please post some datalines as well as the expected output?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 13:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648542#M194301</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-18T13:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648543#M194302</link>
      <description>&lt;P&gt;Are you just saying you want to remove the DROP and RENAME statements?&amp;nbsp; That will keep the original ID and the new one will be named _ID.&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 13:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648543#M194302</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-18T13:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648544#M194303</link>
      <description>&lt;P&gt;What does the variable ID do? It looks like you base your new ID on a variable named "Index" not "ID".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other than that, I assume that you&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;want to assign new IDs to rows without an ID&lt;/LI&gt;
&lt;LI&gt;want to keep the existing ID (or "Index") values&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The program seems to do that, but it depends on the initial values of ID/Index. If your base data contain an ID/Index of 5, then a row with an empty ID/Index, and then a row with an ID/Index of 6, your new data will have two rows with a value of 6. Not good if ID is supposed to be unique.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not know what the data (and the ID) is going to be used for, but one other possibility springs to mind: If your existing data have index values e.g. in the range 1 to 1000, use another range for the new values, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data BSP_2;
  set BSP;
  if missing(ID) then 
    ID=_N_+10000; /* row number plus high value */
run;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 13:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648544#M194303</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-05-18T13:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648546#M194304</link>
      <description>Example:&lt;BR /&gt;DATA BSP;&lt;BR /&gt;LENGTH Name $20 Firstname $20;&lt;BR /&gt;INPUT Name $ Firstname;&lt;BR /&gt;DATALINES;&lt;BR /&gt;Sample Bernd&lt;BR /&gt;Sample Sabine&lt;BR /&gt;Sample Georg&lt;BR /&gt;Sample Heinz;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA work.BSP_2;&lt;BR /&gt;&lt;BR /&gt;SET work.BSP;&lt;BR /&gt;&lt;BR /&gt;RETAIN _ID;&lt;BR /&gt;&lt;BR /&gt;IF Index ~= . THEN _ID = Index;&lt;BR /&gt;&lt;BR /&gt;ELSE DO;&lt;BR /&gt;_ID+1;&lt;BR /&gt;END;&lt;BR /&gt;&lt;BR /&gt;DROP ID;&lt;BR /&gt;&lt;BR /&gt;RENAME _ID = Index;&lt;BR /&gt;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;So, now is correct with Index and ID.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I need the highest Id/Index Number to increment +1 ....</description>
      <pubDate>Mon, 18 May 2020 13:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648546#M194304</guid>
      <dc:creator>SaschaD</dc:creator>
      <dc:date>2020-05-18T13:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648547#M194305</link>
      <description>Ok, I need the max ID instead of 10000.</description>
      <pubDate>Mon, 18 May 2020 13:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648547#M194305</guid>
      <dc:creator>SaschaD</dc:creator>
      <dc:date>2020-05-18T13:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648549#M194307</link>
      <description>&lt;P&gt;You need to update the _ID after every observation to be ready for next one.&lt;/P&gt;
&lt;P&gt;I assume that the variable INDEX is your ID;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.BSP_2;
    SET work.BSP;
    RETAIN _ID;
    IF Index = . then index = _ID;
    ELSE  index = _ID+1;
    _ID = index;  drop _ID; 
 RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 13:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648549#M194307</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-05-18T13:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648550#M194308</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;DATA BSP;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LENGTH Name $20 Firstname $20;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;INPUT Name $ Firstname;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DATALINES;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sample Bernd&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sample Sabine&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sample Georg&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sample Heinz;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Okay, this does not make sense. Your code specifically refers to a variable named INDEX, which does not appear in this data set. You also need to show us the desired output.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 13:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648550#M194308</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-18T13:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I increment my ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648553#M194310</link>
      <description>&lt;P&gt;The reason I used 10000 was that it would make all the generated IDs easily identifiable. But if you a sequence from the max ID instead, it can be done like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select max(ID) into :max_ID from WORK.BSP;
quit;

data bsp_2;
  set bsp;
  retain new_ID &amp;amp;max_ID;
  if missing(ID) then do;
    new_ID+1;
    ID=new_ID;
    end;
  drop new_ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 13:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-increment-my-ID/m-p/648553#M194310</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-05-18T13:50:08Z</dc:date>
    </item>
  </channel>
</rss>

