<?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 do I create a sequential 7 digit unique ID starting with SL using record count in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663579#M198108</link>
    <description>&lt;P&gt;SQL doesn't have a real strong connection to sequence, especially if you expect the first value of a current data set to get a specific value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A data step however does, in fact there is an automatic variable _n_ that is iterated each time the data set does. So this should do what you are requesting. Using the put function with the Z5 format outputs a string&amp;nbsp; of 5 characters with leading 0.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   length  id $ 7;
   id = cats('SL',put(_n_,z5.));
run;
&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Jun 2020 19:45:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-06-19T19:45:53Z</dc:date>
    <item>
      <title>How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663575#M198106</link>
      <description>&lt;P&gt;I need to create something similar to the following for hundreds of records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Have&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Want&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD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R&gt;&lt;TR&gt;&lt;TD&gt;G&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;G&lt;/TD&gt;&lt;TD&gt;SL00007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;SL00008&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;I&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;I&lt;/TD&gt;&lt;TD&gt;SL00009&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;J&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;J&lt;/TD&gt;&lt;TD&gt;SL00010&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;K&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;K&lt;/TD&gt;&lt;TD&gt;SL00011&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a unique 7 digit code for each record starting with SL00001, SL00002, etcetera up to the number of records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been trying things like below to no avail.&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;SELECT COUNT(OBS) AS RecCount&lt;BR /&gt;From WORK.DataSample;&lt;BR /&gt;QUIT;&lt;BR /&gt;DATA WithIDs;&lt;BR /&gt;SET WORK.DataSample;&lt;BR /&gt;OBS = OBS;&lt;BR /&gt;j = N(OBS);&lt;BR /&gt;DO DCL INT i;&lt;BR /&gt;i = 1 TO j BY 1;&lt;BR /&gt;ID = CATS('SL',put(i,z5.));&lt;BR /&gt;OUTPUT;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC PRINT DATA=WithIDs;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 19:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663575#M198106</guid>
      <dc:creator>WB1_2018</dc:creator>
      <dc:date>2020-06-19T19:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663577#M198107</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WithIDs;
SET WORK.DataSample;

ID = CATS('SL',put( _n_  ,z5.));

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maybe just that instead?&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/249273"&gt;@WB1_2018&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to create something similar to the following for hundreds of records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&l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R&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create a unique 7 digit code for each record starting with SL00001, SL00002, etcetera up to the number of records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been trying things like below to no avail.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;SELECT COUNT(OBS) AS RecCount&lt;BR /&gt;From WORK.DataSample;&lt;BR /&gt;QUIT;&lt;BR /&gt;DATA WithIDs;&lt;BR /&gt;SET WORK.DataSample;&lt;BR /&gt;OBS = OBS;&lt;BR /&gt;j = N(OBS);&lt;BR /&gt;DO DCL INT i;&lt;BR /&gt;i = 1 TO j BY 1;&lt;BR /&gt;ID = CATS('SL',put(i,z5.));&lt;BR /&gt;OUTPUT;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC PRINT DATA=WithIDs;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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>Fri, 19 Jun 2020 19:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663577#M198107</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-19T19:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663579#M198108</link>
      <description>&lt;P&gt;SQL doesn't have a real strong connection to sequence, especially if you expect the first value of a current data set to get a specific value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A data step however does, in fact there is an automatic variable _n_ that is iterated each time the data set does. So this should do what you are requesting. Using the put function with the Z5 format outputs a string&amp;nbsp; of 5 characters with leading 0.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   length  id $ 7;
   id = cats('SL',put(_n_,z5.));
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jun 2020 19:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663579#M198108</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-19T19:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663580#M198109</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input OBS $;
cards;
A
B
C
D
E
F
G
H
I
J
K
;

proc sql;
 create table want as
 select *,cats('SL',put(monotonic(),z5.)) as ID
 from have;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jun 2020 19:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663580#M198109</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-06-19T19:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663582#M198110</link>
      <description>&lt;P&gt;Well, that was fast! This is my first time using SAS Community. This appears to work fine though I need to research and understand what monotonic is. Thank you this is really cool!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 19:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663582#M198110</guid>
      <dc:creator>WB1_2018</dc:creator>
      <dc:date>2020-06-19T19:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663596#M198120</link>
      <description>&lt;P&gt;And be aware that the MONOTONIC is undocumented and has no promises of consistent behavior or even presence from release to release of SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 20:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663596#M198120</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-19T20:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663598#M198122</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; I agree however here at my bank where I work, we work with 9.3,9.4 etc and it works fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp; any thoughts from sas inc? Are you opposed to it? Paul D uses a lot, I am going with that confidence as I trust him wholeheartedly&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 20:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663598#M198122</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-06-19T20:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663601#M198125</link>
      <description>&lt;P&gt;I went with monotonic since I have not been able to get&amp;nbsp; _n_ to work. I would use it, if I could.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 20:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663601#M198125</guid>
      <dc:creator>WB1_2018</dc:creator>
      <dc:date>2020-06-19T20:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663603#M198127</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/249273"&gt;@WB1_2018&lt;/a&gt;&amp;nbsp; In most cases monotonic() does work though it's not documented like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; mentioned. Yes, so that does require attention. Let me admit, my true experience in the real world is limited unlike many veterans here whose experience equals my age. lol&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason I posted monotonic() is because -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Many whom I work with are all SQL users who would rather prefer SQL spaghetti code as opposed to any classy SAS syntax&lt;/P&gt;
&lt;P&gt;2. We use 9.3,9.4 in our various departments i.e credit risk, marketing, operations etc. Monotonic() transcends across like bread and butter. So that gave me the confidence to offer&lt;/P&gt;
&lt;P&gt;3. I have seen my Guru&amp;nbsp; Paul D&amp;nbsp;@ hashman&amp;nbsp; offering more than couple of times here, and that gives me even more confidence.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With all the above being mentioned, it's good to be aware just in case!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 20:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663603#M198127</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-06-19T20:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663604#M198128</link>
      <description>I am trying this:&lt;BR /&gt;DATA want;&lt;BR /&gt;SET have;&lt;BR /&gt;LENGTH ID $ 7;&lt;BR /&gt;ID = CATS('SL',put( _n_ ,z5.));&lt;BR /&gt;RUN;&lt;BR /&gt;But get warning errors below. Is it possible that _n_ is wider than 2 digits?&lt;BR /&gt;WARNING: Length of character variable ID has already been set.&lt;BR /&gt;Use the LENGTH statement as the very first statement in the DATA STEP to declare the length of a character variable.&lt;BR /&gt;WARNING: In a call to the CATS function, the buffer allocated for the result was not long enough to contain the concatenation of&lt;BR /&gt;all the arguments. The correct result would contain 7 characters, but the actual result might either be truncated to 1&lt;BR /&gt;character(s) or be completely blank, depending on the calling environment. The following note indicates the left-most&lt;BR /&gt;argument that caused truncation.</description>
      <pubDate>Fri, 19 Jun 2020 20:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663604#M198128</guid>
      <dc:creator>WB1_2018</dc:creator>
      <dc:date>2020-06-19T20:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663614#M198134</link>
      <description>WARNING: Length of character variable ID has already been set.&lt;BR /&gt;&lt;BR /&gt;Do you already have a variable called ID on your data set? If so, choose another name to avoid conflicts.</description>
      <pubDate>Fri, 19 Jun 2020 21:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663614#M198134</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-19T21:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663645#M198152</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/249273"&gt;@WB1_2018&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I am trying this:&lt;BR /&gt;DATA want;&lt;BR /&gt;SET have;&lt;BR /&gt;LENGTH ID $ 7;&lt;BR /&gt;ID = CATS('SL',put( _n_ ,z5.));&lt;BR /&gt;RUN;&lt;BR /&gt;But get warning errors below. Is it possible that _n_ is wider than 2 digits?&lt;BR /&gt;WARNING: Length of character variable ID has already been set.&lt;BR /&gt;Use the LENGTH statement as the very first statement in the DATA STEP to declare the length of a character variable.&lt;BR /&gt;WARNING: In a call to the CATS function, the buffer allocated for the result was not long enough to contain the concatenation of&lt;BR /&gt;all the arguments. The correct result would contain 7 characters, but the actual result might either be truncated to 1&lt;BR /&gt;character(s) or be completely blank, depending on the calling environment. The following note indicates the left-most&lt;BR /&gt;argument that caused truncation.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That almost certainly means that you already have an ID variable that exists in your data set and it is too short to hold 7 characters. Placing the Length ID $ 7. before the SET statement would fix that, as the log says.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We did not mention that because your "picture" of data does not carry any characteristics or if the variable ID even already exists.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 22:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663645#M198152</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-19T22:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663700#M198186</link>
      <description>&lt;P&gt;Here's the thing about&amp;nbsp;&lt;STRONG&gt;monotonic()&lt;/STRONG&gt;.&amp;nbsp; It's not documented, but it is well-known in SAS lore as a way to simulate a "record number" function in PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, it's&amp;nbsp;&lt;STRONG&gt;not&lt;/STRONG&gt; an SQL function.&amp;nbsp; This works too:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
 set sashelp.class;
 recordnum = monotonic();
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you don't need this in a DATA step usually, because you have the _N_ automatic variable.&amp;nbsp; (Although _N_ isn't really "obs number" -- it's the number of times you've been through the implicit loop.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because it's a SAS function and not specific to SQL...you can technically use the function in PROC SQL.&amp;nbsp; But the results are nondeterministic (that is...not predictable) in some SQL contexts where PROC SQL might optimize your query.&amp;nbsp; In general, people find it works okay for the simple example that the OP asked about here.&amp;nbsp; But it's not guaranteed, and would be more likely to break down in a more complex query with joins or passthrough to a database.&amp;nbsp; "Observation numbers" are a concept that makes sense in DATA step and an analytical data context where "order matters" - but they don't make so much sense in a relational data model.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your goal is a unique key for your record, and not an ordinal record number, &lt;A href="https://blogs.sas.com/content/sasdummy/2012/10/19/creating-a-somewhat-unique-id-using-the-uuidgen-function/" target="_self"&gt;consider using the UUIDGEN function&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 13:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663700#M198186</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2020-06-20T13:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a sequential 7 digit unique ID starting with SL using record count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663982#M198315</link>
      <description>&lt;P&gt;Thank you for that great insight! That was the issue (user!). LOL.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2020 13:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-sequential-7-digit-unique-ID-starting-with-SL/m-p/663982#M198315</guid>
      <dc:creator>WB1_2018</dc:creator>
      <dc:date>2020-06-22T13:33:21Z</dc:date>
    </item>
  </channel>
</rss>

