<?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 Add numbering sequence to order each ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-numbering-sequence-to-order-each-ID/m-p/784403#M250319</link>
    <description>&lt;P&gt;I'm not sure the best way to word this, but I essentially just want to add an ordering variable that will indicate the first visit (ORD = 1), second visit (ORD = 2), etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id visit @@;
 cards;
	1	101	1	201	1	301	1	401 
	2	101	2	201	2	401	
	3	201	3	301	3	401	
	4	101	4	301	4	401 
	5	301	5	401 
	6	201 
	7	101	7	201	7	301	7	401 
	8	101	8	401
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id visit @@;
 cards;
	1	101	1	201	1	301	1	401 
	2	101	2	201	2	401	
	3	201	3	301	3	401	
	4	101	4	301	4	401 
	5	301	5	401 
	6	201 
	7	101	7	201	7	301	7	401 
	8	101	8	401
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 06 Dec 2021 21:28:50 GMT</pubDate>
    <dc:creator>mariko5797</dc:creator>
    <dc:date>2021-12-06T21:28:50Z</dc:date>
    <item>
      <title>Add numbering sequence to order each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-numbering-sequence-to-order-each-ID/m-p/784403#M250319</link>
      <description>&lt;P&gt;I'm not sure the best way to word this, but I essentially just want to add an ordering variable that will indicate the first visit (ORD = 1), second visit (ORD = 2), etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id visit @@;
 cards;
	1	101	1	201	1	301	1	401 
	2	101	2	201	2	401	
	3	201	3	301	3	401	
	4	101	4	301	4	401 
	5	301	5	401 
	6	201 
	7	101	7	201	7	301	7	401 
	8	101	8	401
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id visit @@;
 cards;
	1	101	1	201	1	301	1	401 
	2	101	2	201	2	401	
	3	201	3	301	3	401	
	4	101	4	301	4	401 
	5	301	5	401 
	6	201 
	7	101	7	201	7	301	7	401 
	8	101	8	401
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 21:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-numbering-sequence-to-order-each-ID/m-p/784403#M250319</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-12-06T21:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Add numbering sequence to order each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-numbering-sequence-to-order-each-ID/m-p/784404#M250320</link>
      <description>&lt;P&gt;EDIT: data I want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 input id visit @@ ord;
 cards;
	1	101	1	1	201	2	1	301	3	1	401	4 
	2	101	1	2	201	2	2	401	3 
	3	201	1	3	301	2	3	401	3 
	4	101	1	4	301	2	4	401	3 
	5	301	1	5	401	2 
	6	201	1 
	7	101	1	7	201	2	7	301	3	7	401	4 
	8	101	1	8	401	2 
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 21:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-numbering-sequence-to-order-each-ID/m-p/784404#M250320</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-12-06T21:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Add numbering sequence to order each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-numbering-sequence-to-order-each-ID/m-p/784418#M250326</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;/* assumes your data is sorted by ID*/
data want;
   set have;
   by id;
   retain ord;
   if first.id then ord=0;
   ord+1;
run;&lt;/PRE&gt;
&lt;P&gt;If you data is not actually sorted by ID but just grouped use the option NOTSORTED on the By statement.&lt;/P&gt;
&lt;P&gt;By creates automatic variables First. and Last. that you can use to identify if an observation is the first or last of a by group for conditional processing.&lt;/P&gt;
&lt;P&gt;Retain creates a variable whose values are keep across iterations of the data step. The Ord+1; increments the value by one for each step. It is reset to 0 at the beginning of the group so the first value written is 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 23:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-numbering-sequence-to-order-each-ID/m-p/784418#M250326</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-06T23:28:28Z</dc:date>
    </item>
  </channel>
</rss>

