<?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: Ranking character variable values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479023#M286455</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Cust;
input Cust_name $ Manager1 $ Manager1 $ Manager3 $ Manager4 $ Manager5 $;
cards;
Jason Paul . . James Bond
Maxmil Lucien Peter . . Pan
Pogba . . Kit ARYNA Inieata
;
data want;
 set cust;
 array x{*} $ manager:;
 do i=dim(x) to 1 by -1;
  if not missing(x{i}) then do;highest=x{i};call missing(x{i});leave;end;
 end;
 do i=dim(x) to 1 by -1;
  if not missing(x{i}) then do;next_highest=x{i};leave;end;
 end;
 drop i manager:;
 run;
 
 proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 18 Jul 2018 13:08:45 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-07-18T13:08:45Z</dc:date>
    <item>
      <title>Ranking character variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/478995#M286453</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following data set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-18 at 12.37.10.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21816iAB8ECAC9144360E8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-18 at 12.37.10.png" alt="Screen Shot 2018-07-18 at 12.37.10.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The above data set can be created with the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Cust;&lt;BR /&gt;input Cust_name $ Manager1 $ Manager1 $ Manager3 $ Manager4 $ Manager5 $;&lt;BR /&gt;cards;&lt;BR /&gt;Jason Paul . . James Bond&lt;BR /&gt;Maxmil Lucien Peter . . Pan&lt;BR /&gt;Pogba . . Kit ARYNA Inieata&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My objective is to create two variables:&lt;/P&gt;&lt;P&gt;- Highest_Ranked_Manager: the highest ranked manager of each customer&lt;/P&gt;&lt;P&gt;-Next_ranked_manager: The next highest ranked manager.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe this is self explanatory but the expected outcome table is:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-18 at 12.40.53.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21817iA38C603BD588F563/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-18 at 12.40.53.png" alt="Screen Shot 2018-07-18 at 12.40.53.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas on how I can do this please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 11:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/478995#M286453</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-18T11:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking character variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479016#M286454</link>
      <description>&lt;P&gt;If all manager-names have just one word, you could use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set work.CUST;

   length 
      ManagerList $ 50
      Highest_ranked_manager Next_Ranked_Manager $ 8
   ;

   ManagerList = catx(' ', of Manager:);

   Highest_ranked_manager = scan(ManagerList, countw(ManagerList));
   Next_Ranked_Manager = scan(ManagerList, countw(ManagerList)-1);

   keep Cust_name Highest_ranked_manager Next_Ranked_Manager;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to adjust length of variables depending on the real cust dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: If the names are more complex, than please add those cases to the example dataset and we shall see, if the code can be updated or arrays and loops are necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 13:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479016#M286454</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-07-18T13:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking character variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479023#M286455</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Cust;
input Cust_name $ Manager1 $ Manager1 $ Manager3 $ Manager4 $ Manager5 $;
cards;
Jason Paul . . James Bond
Maxmil Lucien Peter . . Pan
Pogba . . Kit ARYNA Inieata
;
data want;
 set cust;
 array x{*} $ manager:;
 do i=dim(x) to 1 by -1;
  if not missing(x{i}) then do;highest=x{i};call missing(x{i});leave;end;
 end;
 do i=dim(x) to 1 by -1;
  if not missing(x{i}) then do;next_highest=x{i};leave;end;
 end;
 drop i manager:;
 run;
 
 proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jul 2018 13:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479023#M286455</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-18T13:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking character variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479097#M286456</link>
      <description>&lt;P&gt;Good idea.&amp;nbsp; You can simplify and make it more robust.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set work.CUST;
   length Highest_ranked_manager Next_Ranked_Manager $50 ;
   Highest_ranked_manager = scan(catx('|', of Manager:), -1,'|');
   Next_Ranked_Manager = scan(catx('|', of Manager:), -2,'|');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't know what length to define the new variables you could let SAS figure it out be replacing the LENGTH statement with two assignment statements.&amp;nbsp; That will make the length match the length of the first variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   Highest_ranked_manager = manager1;
   Next_Ranked_Manager = manager1;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jul 2018 15:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479097#M286456</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-18T15:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking character variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479309#M286457</link>
      <description>&lt;P&gt;HI Andreas, Thanks for the proposed solution. It worked but i got a warning. Im guessing it was because of the use of the countw function. However, when i used the scan(ManagerList, -1) and scan(ManagerList, -2) it worked without a warning&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 22:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking-character-variable-values/m-p/479309#M286457</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-18T22:22:13Z</dc:date>
    </item>
  </channel>
</rss>

