<?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: create seq number for each  ownership structure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982999#M379435</link>
    <description>&lt;P&gt;The newest (date close to today) get value 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Feb 2026 07:53:54 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2026-02-04T07:53:54Z</dc:date>
    <item>
      <title>create seq number for each  ownership structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982992#M379430</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Let's say that Dave(Id number 1) and Suzan(id number 2) are married.&lt;/P&gt;
&lt;P&gt;They want to open a few bank accounts.&lt;/P&gt;
&lt;P&gt;On&amp;nbsp;25JAN2025 Dave+Suzan applied to open bank account&lt;/P&gt;
&lt;P&gt;On 05FEB2026 Dave+Suzan applied to open bank account&lt;/P&gt;
&lt;P&gt;On 01JAN2026 Dave (without Suzan) applied to open bank account&lt;/P&gt;
&lt;P&gt;On 17DEC2025&amp;nbsp;Suzan (without Dave) applied to open bank account&lt;/P&gt;
&lt;P&gt;On 05JAN2025 Suzan (without Dave) applied to open bank account&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see the ownership of the application can be -&amp;nbsp;Dave+Suzan&amp;nbsp; or Dave only or Suzan only&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My task-&lt;/P&gt;
&lt;P&gt;For&amp;nbsp; each&amp;nbsp; ownership I want to create a sequence number by date of application.&lt;/P&gt;
&lt;P&gt;(ownership structure is defined by set of IDS)&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;Here is the data set and want data set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
format date date9.;
input ID	appidentity	date :date9. ;
cards;
1 123 05FEB2026
2 123 05FEB2026
1 999 25JAN2025
2 999 25JAN2025
1 456 01JAN2026
2 678 05JAN2025
2 777 17DEC2025
;
Run;


/**Concateneate IDS to build ownership key**/
/**Rank the applicatioDates with each ownership key(newest=1 so descending)
/**Attach the rank back to all rows**/

proc sort data=have ; by appidentity ;Run;
data Vector_IDS_t(drop=ID);
set have ;
by appidentity;
length Vector_IDS $ 300;
retain Vector_IDS;
Vector_IDS=catx(',',Vector_IDS,ID);
if last.appidentity then do; 
output;
call missing(Vector_IDS);
end;
run;


proc sql;
create table t1 as
select a.*,b.Vector_IDS
from have as a
left join Vector_IDS_t  as b
on a.appidentity=b.appidentity
;
quit;


proc sort data=t1;
by Vector_IDS descending date;
Run;

Data want;
set t1;
by Vector_IDS;
retain order;
if first.Vector_IDS then order=0;
order+1;
Run;

/*Data want;*/
/*format date date9.;*/
/*input ID	appidentity	date :date9.  Order;*/
/*cards;*/
/*1 999 25JAN2025 2*/
/*2 999 25JAN2025 2*/
/*1 123 05FEB2026 1*/
/*2 123 05FEB2026 1*/
/*1 456 01JAN2026 1*/
/*2 678 05JAN2025 1*/
/*2 777 17DEC2025 2*/
/*;*/
/*Run;*/





















 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Feb 2026 07:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982992#M379430</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2026-02-04T07:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: create seq number for each  ownership structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982995#M379432</link>
      <description>Sorry, I don't understand how you wish calculate "order".&lt;BR /&gt;Can elaborate a bit more?</description>
      <pubDate>Wed, 04 Feb 2026 07:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982995#M379432</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2026-02-04T07:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: create seq number for each  ownership structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982997#M379433</link>
      <description>&lt;P&gt;Hi, I found the solution,&lt;/P&gt;
&lt;P&gt;Maybe have other offers for solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
format date date9.;
input ID	appidentity	date :date9. ;
cards;
1 123 05FEB2026
2 123 05FEB2026
1 999 25JAN2025
2 999 25JAN2025
1 456 01JAN2026
2 678 05JAN2025
2 777 17DEC2025
;
Run;

/**Concateneate IDS to build ownership key**/
/**Rank the applicatioDates with each ownership key(newest=1 so descending)
/**Attach the rank back to all rows**/

proc sort data=have ; by appidentity ;Run;
data Vector_IDS_t(drop=ID);
set have ;
by appidentity;
length Vector_IDS $ 300;
retain Vector_IDS;
Vector_IDS=catx(',',Vector_IDS,ID);
if last.appidentity then do; 
output;
call missing(Vector_IDS);
end;
run;


proc sql;
create table t1 as
select distinct a.date,b.Vector_IDS
from have as a
left join Vector_IDS_t  as b
on a.appidentity=b.appidentity
;
quit;

proc sort data=t1;
by Vector_IDS descending date;
Run;

Data t2;
set t1;
by Vector_IDS;
retain order;
if first.Vector_IDS then order=0;
order+1;
Run;


proc sql;
create table t0 as
select a.*,b.Vector_IDS
from have as a
left join Vector_IDS_t  as b
on a.appidentity=b.appidentity
;
quit;


proc sql;
create table want as
select a.*,b.order
from t0 as a
left join t2  as b
on a.Vector_IDS=b.Vector_IDS  and a.date=b.date
;
quit;




/*Data want;*/
/*format date date9.;*/
/*input ID	appidentity	date :date9.  Order;*/
/*cards;*/
/*1 999 25JAN2025 2*/
/*2 999 25JAN2025 2*/
/*1 123 05FEB2026 1*/
/*2 123 05FEB2026 1*/
/*1 456 01JAN2026 1*/
/*2 678 05JAN2025 1*/
/*2 777 17DEC2025 2*/
/*;*/
/*Run;*/


 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 07:35:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982997#M379433</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2026-02-04T07:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: create seq number for each  ownership structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982998#M379434</link>
      <description>&lt;P&gt;Why 999's order number is 2 ? Aren't you count it from past to the future?&lt;/P&gt;
&lt;PRE&gt;Data have;
format date date9.;
input ID	appidentity	date :date9. ;
format date date9.;
cards;
1 123 05FEB2026
2 123 05FEB2026
1 999 25JAN2025
2 999 25JAN2025
1 456 01JAN2026
2 678 05JAN2025
2 777 17DEC2025
;
Run;

proc freq data=have noprint;
table appidentity*id/out=id nopercent;
run;
data new_id;
do until(last.appidentity);
 set id(keep=appidentity id);
 by appidentity;
 length new_id $ 100;
 new_id=catx('|',new_id,id);
end;
drop id;
run;
proc sql;
create table have2 as
select * from have  natural left join new_id 
 order by new_id,date,appidentity;
quit;
data want;
 set have2;
 by new_id date;
 if first.new_id then order=0;
 if first.date then order+1;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Feb 2026 07:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982998#M379434</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-02-04T07:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: create seq number for each  ownership structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982999#M379435</link>
      <description>&lt;P&gt;The newest (date close to today) get value 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 07:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-seq-number-for-each-ownership-structure/m-p/982999#M379435</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2026-02-04T07:53:54Z</dc:date>
    </item>
  </channel>
</rss>

