<?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 add a row number to a table in SAS code? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499918#M248</link>
    <description>&lt;P&gt;If the one field says there are 12 payments and only 3 appear in the data what logic do your propose to make up records for the other 9 payments?&amp;nbsp; What values shoudl the new records have for the other fields?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also do the numbers that exist always go in order like in your example?&amp;nbsp; Or could the 3 payments be numbers 4,7 and 8 of 12 instead of just 1,2 and 3 of 12?&lt;/P&gt;</description>
    <pubDate>Fri, 28 Sep 2018 14:43:26 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-09-28T14:43:26Z</dc:date>
    <item>
      <title>How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499663#M189</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We need to add rows in a sas dataset, the number of rows depends on the difference between two columns and is variable according to an id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is an example in excel, in yellow are the rows needed to be add.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 18:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499663#M189</guid>
      <dc:creator>MariaAguirre</dc:creator>
      <dc:date>2018-09-27T18:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499684#M195</link>
      <description>&lt;P&gt;What two columns are you referencing? You have to be more specific than this if you want a usable answer.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 19:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499684#M195</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-09-27T19:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499687#M198</link>
      <description>Your subject line and question don’t align. What’s the logic for adding those rows? When do you add? How do you know? Show several variations of your logic please.</description>
      <pubDate>Thu, 27 Sep 2018 20:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499687#M198</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-27T20:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499693#M201</link>
      <description>&lt;P&gt;The original dataset have the number of rows of the number of payments till the basedate. I need to have rows equal de number of &lt;SPAN&gt;payments&amp;nbsp;&lt;/SPAN&gt;. In the example attached there are 18 &lt;SPAN&gt;payments&amp;nbsp;&lt;/SPAN&gt;but only 16 rows, so I need to add two more rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The number of rows added will depend of the total number of payments and the maximun payment I see.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 20:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499693#M201</guid>
      <dc:creator>MariaAguirre</dc:creator>
      <dc:date>2018-09-27T20:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499743#M208</link>
      <description>&lt;P&gt;Ok. Please provide sample data as text, so we can work with it. If you cannot, please make some fake data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 00:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499743#M208</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-28T00:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499904#M245</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is an example, the column "cuotas_plan" the total number of payments. The column&amp;nbsp;Nro_Cuota_Plan are the number of payments I see, in the first case there are 12 payments and I see only 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 13:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499904#M245</guid>
      <dc:creator>MariaAguirre</dc:creator>
      <dc:date>2018-09-28T13:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499918#M248</link>
      <description>&lt;P&gt;If the one field says there are 12 payments and only 3 appear in the data what logic do your propose to make up records for the other 9 payments?&amp;nbsp; What values shoudl the new records have for the other fields?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also do the numbers that exist always go in order like in your example?&amp;nbsp; Or could the 3 payments be numbers 4,7 and 8 of 12 instead of just 1,2 and 3 of 12?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 14:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499918#M248</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-28T14:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499933#M250</link>
      <description>&lt;P&gt;What happens to the other values? Are they retained? Especially the last column that seems to change.&lt;/P&gt;
&lt;P&gt;You can use output and BY group processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Set up BY list to specify your groups correctly&lt;/P&gt;
&lt;P&gt;2. At last of each group, check if nro_cuota_plan is less than cuotas_plan. If so, output records and increement nro_cuota_plan until it's full. Otherwise, write same record out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is untested, but you should be able to get this working from here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outputData;
set inputData;
*this is very important;
by &amp;lt;list variables to uniquely identify a group&amp;gt;;

*last variable in the by statement indicates a new group;
if last.var and nro_cuota_plan &amp;lt; cuotas_plan then do ; 
output;
do i=nro_cuota_plan+1 to cuotos_plan;
nro_cuota_plan+1;
output;
end;
end;
else output;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236703"&gt;@MariaAguirre&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attached is an example, the column "cuotas_plan" the total number of payments. The column&amp;nbsp;Nro_Cuota_Plan are the number of payments I see, in the first case there are 12 payments and I see only 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 15:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499933#M250</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-28T15:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499997#M263</link>
      <description>&lt;P&gt;Hi! The new rows will be the "nro_plan_cuotas" I don´t have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the example and it didn´t work...&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 18:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/499997#M263</guid>
      <dc:creator>MariaAguirre</dc:creator>
      <dc:date>2018-09-28T18:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500000#M264</link>
      <description>&lt;P&gt;Post the code you tried. I did state you needed to complete some portions which I assume you did.&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/236703"&gt;@MariaAguirre&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi! The new rows will be the "nro_plan_cuotas" I don´t have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the example and it didn´t work...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 18:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500000#M264</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-28T18:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500006#M266</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; outputData&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; work.example&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token comment"&gt;*this is very important;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;contrato_id&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token comment"&gt;*last variable in the by statement indicates a new group;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; last&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; and nro_cuota_plan &lt;SPAN class="token operator"&gt;&amp;lt;&lt;/SPAN&gt; cuotas_plan &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; do &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
output&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
do i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;nro_cuota_plan&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to cuotas_plan&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
nro_cuota_plan&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
output&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; output&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 18:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500006#M266</guid>
      <dc:creator>MariaAguirre</dc:creator>
      <dc:date>2018-09-28T18:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500012#M267</link>
      <description>if last.var -&amp;gt; this needs to reference your variable. &lt;BR /&gt;SO it should be&lt;BR /&gt;if last.contrato_id. Then it works fine.&lt;BR /&gt;&lt;BR /&gt;Please read up on BY group processing, FIRST/LAST automatic variables so you understand what's happening.</description>
      <pubDate>Fri, 28 Sep 2018 19:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500012#M267</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-28T19:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500013#M268</link>
      <description>&lt;P&gt;Your FIRST. reference and BY statements need match.&lt;/P&gt;
&lt;P&gt;Also you could probably eliminate the extra variable I and just use your other variable in the DO loop.&lt;/P&gt;
&lt;P&gt;But I suspect that do will want to set one or more of the variables to missing for these extra observations, depending on their meaning.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outputData;
  set work.example;
  by contrato_id;
  output;
  if last.contrato_id then do nro_cuota_plan=nro_cuota_plan+1 to coutas_plan;
* Should any of the variable be set missing? ;
*   call missing(x , y) ;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 19:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500013#M268</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-28T19:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500025#M271</link>
      <description>&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 20:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500025#M271</guid>
      <dc:creator>MariaAguirre</dc:creator>
      <dc:date>2018-09-28T20:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a row number to a table in SAS code?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500027#M272</link>
      <description>&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 20:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-add-a-row-number-to-a-table-in-SAS-code/m-p/500027#M272</guid>
      <dc:creator>MariaAguirre</dc:creator>
      <dc:date>2018-09-28T20:32:40Z</dc:date>
    </item>
  </channel>
</rss>

