<?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 replication number to a loop variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829716#M327824</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need;
set have;
retain replication 0;

if entryNumber=1 then replication+1;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 22 Aug 2022 19:01:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-08-22T19:01:05Z</dc:date>
    <item>
      <title>How do I create a replication number to a loop variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829711#M327821</link>
      <description>&lt;P&gt;Greetings everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that is generated from replications and I need to add a replication number to each set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;input entrynumber var1 var2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1 -1.189 -2.655&lt;/P&gt;&lt;P&gt;2 -0.735 -1.896&lt;/P&gt;&lt;P&gt;3 0.452 0-0.984&lt;/P&gt;&lt;P&gt;1 -0.291 1.998&lt;/P&gt;&lt;P&gt;2 0.003 -0.015&lt;/P&gt;&lt;P&gt;3 1.267 2.974&lt;/P&gt;&lt;P&gt;1 0.192 -0.523&lt;/P&gt;&lt;P&gt;2 -1.715 -0.569&lt;/P&gt;&lt;P&gt;3 2.876 1.998&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data need;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;input entrynumber var1 var2 replication;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1 -1.189 -2.655 1&lt;/P&gt;&lt;P&gt;2 -0.735 -1.896 1&lt;/P&gt;&lt;P&gt;3 0.452 0-0.984 1&lt;/P&gt;&lt;P&gt;1 -0.291 1.998 2&lt;/P&gt;&lt;P&gt;2 0.003 -0.015 2&lt;/P&gt;&lt;P&gt;3 1.267 2.974 2&lt;/P&gt;&lt;P&gt;1 0.192 -0.523 3&lt;/P&gt;&lt;P&gt;2 -1.715 -0.569 3&lt;/P&gt;&lt;P&gt;3 2.876 1.998 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I achieve this? Do I use do loop?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any input will be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 18:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829711#M327821</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-08-22T18:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a replication number to a loop variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829714#M327822</link>
      <description>&lt;P&gt;First, make sure that your data step generates the values you intend. This line is malformed to read with that input as 0-0.984 is not a valid number.&lt;/P&gt;
&lt;PRE&gt;3 0.452 0-0.984 1&lt;/PRE&gt;
&lt;P&gt;Second, it is a good idea to paste code into a code box opened on the forum with the &amp;lt;/&amp;gt; icon that appears along the top of the message window. The body text of the message windows will get reformatted by the forum software and may insert/remove/replace characters so that an data step will not run correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know exactly how many records are in each replicate and the value is in the data as shown:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  retain replicate 1;
  output;
  if entrynumber=3 then replicate+1;
run;&lt;/PRE&gt;
&lt;P&gt;Retain creates variables that maintain values across iterations of the data step and optionally assign a starting value.&lt;/P&gt;
&lt;P&gt;The explicit output writes data to the output set before comparing the value of enterynumber to increment the replicate number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, depending on what/why the data is created if you use Proc Surveyselect to create a replicate sample then it will insert a replicate number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 18:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829714#M327822</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-22T18:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a replication number to a loop variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829715#M327823</link>
      <description>&lt;P&gt;What is the rule to determine when you increment the replication number? In this simple example, it could be a couple of things. What is the real world rule to use on your data?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 18:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829715#M327823</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-22T18:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a replication number to a loop variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829716#M327824</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need;
set have;
retain replication 0;

if entryNumber=1 then replication+1;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Aug 2022 19:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829716#M327824</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-22T19:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a replication number to a loop variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829718#M327826</link>
      <description>Thank you so much for your help. I did not know that I can paste code into a code box here. I will do that in the future.&lt;BR /&gt;&lt;BR /&gt;For this sample run, I only set 50 replications (but I only used 3 in the data example here). I have tried your code but all the 'replicate' variable is 1 instead of 1, 1, 1, 2, 2, 2, 3, 3, 3. Is there something that I have missed?&lt;BR /&gt;&lt;BR /&gt;Thanks again.</description>
      <pubDate>Mon, 22 Aug 2022 19:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829718#M327826</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-08-22T19:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a replication number to a loop variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829719#M327827</link>
      <description>This data set shows results from 3 replications. Each replication contains 3 observations. I am testing my code before I increase the number of replications but haven't been successful.</description>
      <pubDate>Mon, 22 Aug 2022 19:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829719#M327827</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-08-22T19:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a replication number to a loop variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829731#M327838</link>
      <description>&lt;P&gt;If it is always 3 replications, then the code provided by others is fine.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 20:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829731#M327838</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-22T20:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a replication number to a loop variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829732#M327839</link>
      <description>&lt;P&gt;If the number of reps is variable, use the method of incrementing when it's 1, rather than at the end, demonstrated in my solution.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 20:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-replication-number-to-a-loop-variable/m-p/829732#M327839</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-22T20:08:23Z</dc:date>
    </item>
  </channel>
</rss>

