<?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 to assign hierarchical order number in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514227#M2688</link>
    <description>&lt;P&gt;Welcome to the SAS community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you be a bit more specific about the logic here? Why is&amp;nbsp;&lt;SPAN&gt;hierarchical_order equal to 2 in the first row? And 3 in the second?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Nov 2018 11:58:11 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-11-18T11:58:11Z</dc:date>
    <item>
      <title>How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514226#M2687</link>
      <description>&lt;P&gt;Hello! I&amp;nbsp;have a dataset with several entities that belong to a group and I would like to assign a value to each entity to reflect their position within the group (e.g. 1 for the mother company, 2 for the daughters and so on). I would need a loop to cover all the records in the dataset. I can have multiple datasets so I would need to write code that could be applicable to different cases. Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Initial data set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Company&lt;/TD&gt;&lt;TD&gt;Direct_parent&lt;/TD&gt;&lt;TD&gt;Group_parent&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;E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&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;J&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is that the initial data set can vary. It may have 10 companies or 50. So I was trying to build a one size fits all code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help on how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&lt;/P&gt;&lt;P&gt;Matos&lt;/P&gt;</description>
      <pubDate>Sun, 18 Nov 2018 11:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514226#M2687</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2018-11-18T11:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514227#M2688</link>
      <description>&lt;P&gt;Welcome to the SAS community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you be a bit more specific about the logic here? Why is&amp;nbsp;&lt;SPAN&gt;hierarchical_order equal to 2 in the first row? And 3 in the second?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Nov 2018 11:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514227#M2688</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-11-18T11:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514236#M2690</link>
      <description>&lt;P&gt;Sure! In my example the logic is the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Company E is at the top since Group_Parent = E. Thus the hierarchical_order assigned to Company E is 1 (first level of the organization).&lt;/P&gt;&lt;P&gt;Company A, C and G are owned directly by Company E (which is at first level). Thus&amp;nbsp;the&amp;nbsp;hierarchical_order assigned to&amp;nbsp;them is 2&amp;nbsp;(second level of the organization).&lt;/P&gt;&lt;P&gt;Company B and&amp;nbsp;H are owned directly by Company A (which is at the second level). Thus&amp;nbsp;the&amp;nbsp;hierarchical_order assigned to&amp;nbsp;them is&amp;nbsp;3 (third&amp;nbsp;level of the organization). And so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This&amp;nbsp;would be the organizational chart:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture.PNG" style="width: 523px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25024i28815331FDF1145C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The hierarchical order assigned to a company will be dependent from the hierarchical order assigned to its direct parent company.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Nov 2018 14:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514236#M2690</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2018-11-18T14:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514245#M2692</link>
      <description>&lt;P&gt;looking at your hierarchical order company ownership has nothing to do with the decision making process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if company = 'E' then hierarchical_order = 1;&lt;/P&gt;
&lt;P&gt;else&amp;nbsp;&lt;SPAN&gt;if company in ('A','C','G') then hierarchical_order = 2;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;else&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;if company in ('B','H') then hierarchical_order = 3;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;else&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;if company in ('D','F'') then hierarchical_order = 4;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;else &lt;SPAN&gt;if company in ('J','I') then hierarchical_order = 5;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else hierarchical_order = .;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You could also use a format statement to assign the hierarchical_order&lt;/P&gt;</description>
      <pubDate>Sun, 18 Nov 2018 15:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514245#M2692</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-18T15:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514258#M2696</link>
      <description>&lt;P&gt;Many thanks. However, this only works for this specific dataset. My problem is that my dataset is not stable since it is a result of a previous query that I need to run multiple times. As such it is dynamic and I don't know what will be the ownership structure. I&amp;nbsp;will have to deal with datasets&amp;nbsp;with&amp;nbsp;10 different company names or even 60 different company names. Some could&amp;nbsp;end up to&amp;nbsp;20 hierachical order. Is it possible to define a code that could suit to different datasets, with different sizes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another example: here Company E has been replaced by Company O.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Company&lt;/TD&gt;&lt;TD&gt;Direct_parent&lt;/TD&gt;&lt;TD&gt;Group_parent&lt;/TD&gt;&lt;TD&gt;hierarchical_order&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;J&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;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width: 596px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25028i7FEF4FFAD02A8F34/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Nov 2018 16:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514258#M2696</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2018-11-18T16:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514319#M2711</link>
      <description>&lt;P&gt;based on the 2 samples that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/247128"&gt;@Matos&lt;/a&gt; has provided I do not see any relationship in the samples.&amp;nbsp; My reasoning is because A is a child to E in sample one, then in sample 2 E is the child to A.&amp;nbsp; If A is representing the same company in both samples then maybe you want to rethink the process and setup multipedal formats that you would call append based on the incoming dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 01:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514319#M2711</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-19T01:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514323#M2714</link>
      <description>&lt;P&gt;Sound like you want to depth of the node in a tree search.&lt;/P&gt;
&lt;P&gt;Do you have SAS/OR licensed? Can you run PROC NETDRAW?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 02:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514323#M2714</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-19T02:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514356#M2722</link>
      <description>Sorry. In the second example all letters are related with different companies. Iam design with datasets with different group structures and different names. I just used letters instead of names but this should not change the end result.</description>
      <pubDate>Mon, 19 Nov 2018 07:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514356#M2722</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2018-11-19T07:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514417#M2730</link>
      <description>&lt;P&gt;Try this one:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EDITED&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs;
input (Company	Direct_parent	Group_parent ) ($);
rename 	Company=_end	Direct_parent=_start;
cards;
O	 .	O	 
H	O	O	 
J	O	O	 
X	O	O	 
A	H	O	 
C	H	O	 
M	X	O	 
E	A	O	 
F	A	O	 
Z	M	O	 
K	E	O	 
J	E	O	 
I	K	O	 
N	I	O	 
D	I	O	 
G	I	O	 
L	I	O	 
P	G	O	 
V	P	O	 
Q	P	O	 
R	P	O	 
;
run;


 
%let start=O;
data want(keep=path);
if _n_ eq 1 then do;
length path _path  $ 800 ;
if 0 then set have;
declare hash ha(hashexp:20,dataset:'have(where=(_start is not missing and _end is not missing))',multidata:'y');
ha.definekey('_start');
ha.definedata('_end');
ha.definedone();

declare hash pa(ordered:'y');
declare hiter hi_path('pa');
pa.definekey('n');
pa.definedata('n','path');
pa.definedone();

end;


set have(where=(_start="&amp;amp;start"));
count=1;n=1;_n=1;
path=catx('|',_start,_end);
*putlog 'WARNING:Found  ' _end;
   
pa.add();output;
do while(hi_path.next()=0);
 if n ne 1 then pa.remove(key:_n);_n=n;
 _path=path;   
 _start=scan(path,-1,'|');
 rc=ha.find();  /* if rc ne 0 then output; */
 do while(rc=0);
  if not findw(path,strip(_end),'|') then do;
   if length(path)+length(_end)+1 gt lengthc(path) then do;
    putlog 'ERROR: The length of path and _path are set too short';
    stop;
   end;
   
   *putlog 'WARNING:Found  ' _end;
   count+1;n=count;
   path=catx('|',path,_end);
   pa.add(); output;
   path=_path;
 end; /*  else output; It is a circle.*/
  rc=ha.find_next();
end;
end;
pa.clear();

run;

data key;
 set want;
 do order=1 to countw(path);
  key=scan(path,order,'|');lag_key=lag(key);
  if order=1 then lag_key=' ';output;
 end;
 drop path;
run;

data final_want;
 if _n_=1 then do;
   if 0 then set key;
   declare hash h(dataset:'key');
   h.definekey('lag_key','key');
   h.definedata('order');
   h.definedone();
 end;
set have;
call missing(order);
rc=h.find(key:_start,key:_end);
drop rc key lag_key;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 13:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514417#M2730</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-11-19T13:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514418#M2731</link>
      <description>&lt;P&gt;You need to change&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; start&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;E&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;According to&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Group_parent .&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 12:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514418#M2731</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-11-19T12:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514421#M2732</link>
      <description>&lt;P&gt;For the another example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs;
input (Company	Direct_parent	Group_parent ) ($);
rename 	Company=_end	Direct_parent=_start;
cards;
A	E	E
B	A	E
C	E	E
D	B	E
E	. 	E
F	B	E
G	E	E
H	A	E
I	D	E
J	D	E
;
run;


 
%let start=E; /***&amp;lt;---------****/
data want(keep=path);
if _n_ eq 1 then do;
length path _path  $ 800 ;
if 0 then set have;
declare hash ha(hashexp:20,dataset:'have(where=(_start is not missing and _end is not missing))',multidata:'y');
ha.definekey('_start');
ha.definedata('_end');
ha.definedone();

declare hash pa(ordered:'y');
declare hiter hi_path('pa');
pa.definekey('n');
pa.definedata('n','path');
pa.definedone();

end;


set have(where=(_start="&amp;amp;start"));
count=1;n=1;_n=1;
path=catx('|',_start,_end);
*putlog 'WARNING:Found  ' _end;
   
pa.add();output;
do while(hi_path.next()=0);
 if n ne 1 then pa.remove(key:_n);_n=n;
 _path=path;   
 _start=scan(path,-1,'|');
 rc=ha.find();  /* if rc ne 0 then output; */
 do while(rc=0);
  if not findw(path,strip(_end),'|') then do;
   if length(path)+length(_end)+1 gt lengthc(path) then do;
    putlog 'ERROR: The length of path and _path are set too short';
    stop;
   end;
   
   *putlog 'WARNING:Found  ' _end;
   count+1;n=count;
   path=catx('|',path,_end);
   pa.add(); output;
   path=_path;
 end; /*  else output; It is a circle.*/
  rc=ha.find_next();
end;
end;
pa.clear();

run;

data key;
 set want;
 do order=1 to countw(path);
  key=scan(path,order,'|');lag_key=lag(key);
  if order=1 then lag_key=' ';output;
 end;
 drop path;
run;

data final_want;
 if _n_=1 then do;
   if 0 then set key;
   declare hash h(dataset:'key');
   h.definekey('lag_key','key');
   h.definedata('order');
   h.definedone();
 end;
set have;
call missing(order);
rc=h.find(key:_start,key:_end);
drop rc key lag_key;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Nov 2018 13:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514421#M2732</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-11-19T13:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514457#M2742</link>
      <description>&lt;P&gt;It works perfectly! Many thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 14:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514457#M2742</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2018-11-19T14:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign hierarchical order number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514458#M2743</link>
      <description>Works now for different group structures. Just need to change, as you mentioned, the Group_parent.</description>
      <pubDate>Mon, 19 Nov 2018 14:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-hierarchical-order-number/m-p/514458#M2743</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2018-11-19T14:45:51Z</dc:date>
    </item>
  </channel>
</rss>

