<?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: Distinct Row numbers to dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640732#M190924</link>
    <description>loan_num	date1	Row_Num&lt;BR /&gt;111	11Jun2019	1&lt;BR /&gt;111	11Jul2019	0&lt;BR /&gt;112	11Aug2019	1&lt;BR /&gt;113	11Sep2019	1&lt;BR /&gt;113	11Oct2019	0&lt;BR /&gt;114	11Oct2019	1</description>
    <pubDate>Fri, 17 Apr 2020 13:58:11 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2020-04-17T13:58:11Z</dc:date>
    <item>
      <title>Distinct Row numbers to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640730#M190922</link>
      <description>data have;
input loan_num $  date1  date9.;
format date1  date9.;

datalines;
111 11jun2019
111 11jul2019
112 11aug2019
113 11sep2019
113 11oct2019
114 11oct2019
;run;
Produces
111 11jun2019
111 11jul2019
112 11aug2019
113 11sep2019
113 11oct2019
114 11oct2019
I need to assign a row number to each distinct Loan_num such as
loan_num	date1	Row_Num
111	11Jun2019	1
111	11Jul2019	0
112	11Aug2019	1
113	11Sep2019	1
113	11Oct2019	0
114	11Oct2019	1
If the loan_num only appears once, assign a 1.  If the loan_num appears twice, assign a 1 to the first one and a 0 to any subsequent loan_num</description>
      <pubDate>Fri, 17 Apr 2020 13:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640730#M190922</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-04-17T13:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Row numbers to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640732#M190924</link>
      <description>loan_num	date1	Row_Num&lt;BR /&gt;111	11Jun2019	1&lt;BR /&gt;111	11Jul2019	0&lt;BR /&gt;112	11Aug2019	1&lt;BR /&gt;113	11Sep2019	1&lt;BR /&gt;113	11Oct2019	0&lt;BR /&gt;114	11Oct2019	1</description>
      <pubDate>Fri, 17 Apr 2020 13:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640732#M190924</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-04-17T13:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Row numbers to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640736#M190925</link>
      <description>&lt;P&gt;Please try below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input loan_num $ date1 date9.; 
format date1 date9.; datalines; 
111 11jun2019 
111 11jul2019 
112 11aug2019 
113 11sep2019 
113 11oct2019 
114 11oct2019 
;
run; 

proc sort data=have;
by loan_num date1;
run;

data want;
set have;
by loan_num date1;
if first.loan_num then Row_Num=1;
else Row_Num=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 14:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640736#M190925</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-17T14:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Row numbers to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640737#M190926</link>
      <description>&lt;P&gt;&lt;STRONG&gt;PLEASE&lt;/STRONG&gt; do not (and I mean &lt;STRONG&gt;NOT&lt;/STRONG&gt;) post code into the main posting window, or c**p like this happens:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;data have; input loan_num $ date1 date9.; format date1 date9.; datalines; 111 11jun2019 111 11jul2019 112 11aug2019 113 11sep2019 113 11oct2019 114 11oct2019 ;run; Produces 111 11jun2019 111 11jul2019 112 11aug2019 113 11sep2019 113 11oct2019 114 11oct2019 I need to assign a row number to each distinct Loan_num such as loan_num date1 Row_Num 111 11Jun2019 1 111 11Jul2019 0 112 11Aug2019 1 113 11Sep2019 1 113 11Oct2019 0 114 11Oct2019 1 If the loan_num only appears once, assign a 1. If the loan_num appears twice, assign a 1 to the first one and a 0 to any subsequent loan_num&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use the "little running man" instead, it's next to the &amp;lt;/&amp;gt; marked here:&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.png"&gt;&lt;img src="https://communities.sas.com/skins/images/2FD96521DCF95C42FE57BF2A7CB72678/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-04-07 um 08.32.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;It's not rocket science, and it won't make your head explode. Promised.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To your question:&lt;/P&gt;
&lt;P&gt;sort the data by loan_num and whatever you want as an additional sort order, and then, in a subsequent data step, do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by loan_num;
newvar = first.loan_num;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That's all.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 14:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Row-numbers-to-dataset/m-p/640737#M190926</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-17T14:47:08Z</dc:date>
    </item>
  </channel>
</rss>

