<?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: Probability of multiple targets (106 levels) and choosing the probability of target level assign in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Probability-of-multiple-targets-106-levels-and-choosing-the/m-p/566070#M159027</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146403"&gt;@harsh0404&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1x70jnnpttwy0n1gf5rvuivgyry.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;VVALUEX function&lt;/A&gt; might come closest to your attempt using CATS. An approach using arrays would avoid numeric-to-character and character-to-numeric conversion, but you would need to determine the (numeric) array index from the I_TARGET value. Please see an example of both approaches below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id p_targeta p_targetb p_targetc i_target $;
cards;
999 0.1 0.2 0.3 b
;

/* Approach 1: VVALUEX function */

data want;
set have;
px=input(vvaluex(cats('p_target'||i_target)),32.);
run;

/* Approach 2: Array */

data want;
set have;
array pr[*] p_target:;
px=pr[rank(i_target)-96];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We would need to know the real variable and target names to give you more specific advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Your sample data and description suggest that Px might always (?) be the maximum of P_Targeta, P_Targetb, etc., in which case&amp;nbsp;&lt;FONT face="courier new,courier"&gt;px=max(of p_target:)&lt;/FONT&gt; would, of course, be the easiest solution.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Jun 2019 22:08:45 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-06-13T22:08:45Z</dc:date>
    <item>
      <title>Probability of multiple targets (106 levels) and choosing the probability of target level assigned</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Probability-of-multiple-targets-106-levels-and-choosing-the/m-p/566041#M159024</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="delete7.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30268iD47BED4D48BF32C5/image-size/large?v=v2&amp;amp;px=999" role="button" title="delete7.PNG" alt="delete7.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;I have 106 target levels here, this is just small example. SAS gives me a predicted probability of all target levels and classifies them into one of the target levels.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is to create a new variable px that writes probability of only that target which sas classified into. for example for id 101 with target level of &lt;STRONG&gt;b&lt;/STRONG&gt;, sas classified it into &lt;STRONG&gt;c.&amp;nbsp;&lt;/STRONG&gt;So I want px to have a probability of &lt;STRONG&gt;c&lt;/STRONG&gt;, which is &lt;STRONG&gt;P_Targetc.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my code -&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
ALTER TABLE data1
ADD p varchar;
run; 

proc sql;
UPDATE data1
SET p= 'P_Target'; 

data data2 ;
set data1 ; 
px2 = cats (p,Target);
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What i get after this is -&amp;nbsp;&lt;/P&gt;&lt;P&gt;px =&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="delete8.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30269i49BC771ECCEC6C5D/image-size/large?v=v2&amp;amp;px=999" role="button" title="delete8.PNG" alt="delete8.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 20:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Probability-of-multiple-targets-106-levels-and-choosing-the/m-p/566041#M159024</guid>
      <dc:creator>harsh0404</dc:creator>
      <dc:date>2019-06-13T20:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Probability of multiple targets (106 levels) and choosing the probability of target level assign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Probability-of-multiple-targets-106-levels-and-choosing-the/m-p/566061#M159025</link>
      <description>&lt;P&gt;It will help to provide some actual data not a picture.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know of at least one way to do this in a data step involving arrays which means that it doesn't translate easily into Proc Sql code and would likely be extremely verbose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A short example:&lt;/P&gt;
&lt;PRE&gt;data have;
   input id var_a var_b var_c index :$1.;
datalines;
1  .04 .6 .33 a
2  .2  .3 .8  c
3  .1  .2 .3  b
;

data want;
   set have;
   array v var_a var_b var_c;
   array c{3} $ 1 _temporary_ ('a','b','c');
   px = v[whichc(index, of c(*))];
run;
 &lt;/PRE&gt;
&lt;P&gt;Key elements the order of the variables in the array v is associated with the order of the index (target level) values and there better be a matching number. If you have 15 variables but only 5 levels,&amp;nbsp; or 5 variables and 15 levels you need to tell us now as their will likely be lots of additional issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The case of the values in the temporary list has to match the values of your target level.&lt;/P&gt;
&lt;P&gt;The WHICHC function searches for the character&amp;nbsp;value of the first parameter in a list following and returns the position found. With 3 variables it would be easy to just list the variables but if you have dozens that gets pretty long an the array becomes a better choice. Proc SQL does not allow use of variables. Using the returned position selects the value from the array with the correct index if everything is in order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the target level is ever missing you would want to test for that an not do the assignment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the&amp;nbsp; variables in the temporary array are not written to the data set.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 21:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Probability-of-multiple-targets-106-levels-and-choosing-the/m-p/566061#M159025</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-13T21:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: Probability of multiple targets (106 levels) and choosing the probability of target level assign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Probability-of-multiple-targets-106-levels-and-choosing-the/m-p/566070#M159027</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146403"&gt;@harsh0404&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1x70jnnpttwy0n1gf5rvuivgyry.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;VVALUEX function&lt;/A&gt; might come closest to your attempt using CATS. An approach using arrays would avoid numeric-to-character and character-to-numeric conversion, but you would need to determine the (numeric) array index from the I_TARGET value. Please see an example of both approaches below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id p_targeta p_targetb p_targetc i_target $;
cards;
999 0.1 0.2 0.3 b
;

/* Approach 1: VVALUEX function */

data want;
set have;
px=input(vvaluex(cats('p_target'||i_target)),32.);
run;

/* Approach 2: Array */

data want;
set have;
array pr[*] p_target:;
px=pr[rank(i_target)-96];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We would need to know the real variable and target names to give you more specific advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Your sample data and description suggest that Px might always (?) be the maximum of P_Targeta, P_Targetb, etc., in which case&amp;nbsp;&lt;FONT face="courier new,courier"&gt;px=max(of p_target:)&lt;/FONT&gt; would, of course, be the easiest solution.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 22:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Probability-of-multiple-targets-106-levels-and-choosing-the/m-p/566070#M159027</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-06-13T22:08:45Z</dc:date>
    </item>
  </channel>
</rss>

