<?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 create new variables based on ranking of multiple variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509353#M1771</link>
    <description>&lt;P&gt;32 Bit machine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Score_A	Score_B	Score_C	Score_D	Score_F;
cards;
1	0.9	0	0.6	0.6
0	0.2	0.6	1	1
;

data want;
set have;
array s(*)score_a--score_f;
array top(5) ;
array r[*] top5-top1;
call poke(put(peekc(addr(s(1)),40),40.),addr(top[1]), 40);
call sortn(of r[*]);
/*drop top5 top6;*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;64 Bit Machine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Score_A	Score_B	Score_C	Score_D	Score_F;
cards;
1	0.9	0	0.6	0.6
0	0.2	0.6	1	1
;

data want;
set have;
array s(*)score_a--score_f;
array top(5) ;
array r[*] top5-top1;
call pokelong(put(peekclong(addrlong(s(1)),40),40.),addrlong(top[1]), 40);
call sortn(of r[*]);
/*drop top5 top6;*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 31 Oct 2018 21:31:14 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-10-31T21:31:14Z</dc:date>
    <item>
      <title>How to create new variables based on ranking of multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509331#M1765</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to know what SAS codes I can use to decide the values of three ranking variables (Top1 to Top3) based on multiple existing variables (Score_A to F) as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Score_A to F are the scores for A, B, C, D, F for each observation. Top1 to 3 are the new variables that I want to create to show among ABCDF, which would go to top1 to top 3 for each observation. Case 1 assigns only one to each of the new variables and Case 2 would assign two if they have the same scores. Thank you in advanced!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case1&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Top1&lt;/TD&gt;&lt;TD&gt;Top2&lt;/TD&gt;&lt;TD&gt;Top3&lt;/TD&gt;&lt;TD&gt;Score_A&lt;/TD&gt;&lt;TD&gt;Score_B&lt;/TD&gt;&lt;TD&gt;Score_C&lt;/TD&gt;&lt;TD&gt;Score_D&lt;/TD&gt;&lt;TD&gt;Score_F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;obs1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0.9&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;obs2&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0.2&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Top1&lt;/TD&gt;&lt;TD&gt;Top2&lt;/TD&gt;&lt;TD&gt;Top3&lt;/TD&gt;&lt;TD&gt;Score_A&lt;/TD&gt;&lt;TD&gt;Score_B&lt;/TD&gt;&lt;TD&gt;Score_C&lt;/TD&gt;&lt;TD&gt;Score_D&lt;/TD&gt;&lt;TD&gt;Score_F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;obs1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;D F&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0.9&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;obs2&lt;/TD&gt;&lt;TD&gt;D F&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0.2&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 31 Oct 2018 21:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509331#M1765</guid>
      <dc:creator>LimM</dc:creator>
      <dc:date>2018-10-31T21:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create new variables based on ranking of multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509353#M1771</link>
      <description>&lt;P&gt;32 Bit machine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Score_A	Score_B	Score_C	Score_D	Score_F;
cards;
1	0.9	0	0.6	0.6
0	0.2	0.6	1	1
;

data want;
set have;
array s(*)score_a--score_f;
array top(5) ;
array r[*] top5-top1;
call poke(put(peekc(addr(s(1)),40),40.),addr(top[1]), 40);
call sortn(of r[*]);
/*drop top5 top6;*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;64 Bit Machine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Score_A	Score_B	Score_C	Score_D	Score_F;
cards;
1	0.9	0	0.6	0.6
0	0.2	0.6	1	1
;

data want;
set have;
array s(*)score_a--score_f;
array top(5) ;
array r[*] top5-top1;
call pokelong(put(peekclong(addrlong(s(1)),40),40.),addrlong(top[1]), 40);
call sortn(of r[*]);
/*drop top5 top6;*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Oct 2018 21:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509353#M1771</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-31T21:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create new variables based on ranking of multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509363#M1773</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/238280"&gt;@LimM&lt;/a&gt;&amp;nbsp;Welcome to SAS forum. The above is a little incomplete for the reason you need whichn/vname. Me being too lazy didn't do that part although you will get that from someone. Nonetheless, i encourage you to try the remaining&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 21:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509363#M1773</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-31T21:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to create new variables based on ranking of multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509402#M1776</link>
      <description>&lt;P&gt;Much easier if you transpose first&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Obs Score_A	Score_B	Score_C	Score_D	Score_F;
cards;
1 1	0.9	0	0.6	0.6
2 0	0.2	0.6	1	1
;

proc transpose data=have out=scores name=score;
by obs;
var Score_A -- Score_F;
run;

proc sort data=scores; by obs descending col1 score;

data want;
id = 0;
do until(last.obs);
    set scores; by obs descending col1;
    if first.col1 then Id = Id + 1;
    array top{5} $10;
    top{Id} = catx(" ", top{Id}, substr(score, 7, 1));
    end;
keep obs top1-top3;
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Nov 2018 02:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-new-variables-based-on-ranking-of-multiple/m-p/509402#M1776</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-11-01T02:59:16Z</dc:date>
    </item>
  </channel>
</rss>

