<?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 How do i get values based on priority in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364631#M86500</link>
    <description>&lt;P&gt;I have data like this&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a,b,c&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e,f,c&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d,e,f&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want output like&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;max_value&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a,b,c &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e,f,c &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d,e,f &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;considering the order of priority from a-z &amp;nbsp;and a being highest.&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;Thanks,&lt;/P&gt;&lt;P&gt;Jay&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jun 2017 15:50:38 GMT</pubDate>
    <dc:creator>jb9977</dc:creator>
    <dc:date>2017-06-06T15:50:38Z</dc:date>
    <item>
      <title>How do i get values based on priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364631#M86500</link>
      <description>&lt;P&gt;I have data like this&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a,b,c&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e,f,c&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d,e,f&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want output like&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;max_value&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a,b,c &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e,f,c &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d,e,f &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;considering the order of priority from a-z &amp;nbsp;and a being highest.&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;Thanks,&lt;/P&gt;&lt;P&gt;Jay&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364631#M86500</guid>
      <dc:creator>jb9977</dc:creator>
      <dc:date>2017-06-06T15:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do i get values based on priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364636#M86503</link>
      <description>&lt;P&gt;assuming your values are actually single lower-case letters than this works for the provided example.&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines truncover;
  informat id best5. value $10.;
  input id  value ;
datalines;
1 a,b,c
2 e,f,c
3 d,e,f
;
run;

data want;
   set have;
   max_value= 'z';
   do i = 1 to (length(value));
     if substr(value,i,1) &amp;lt; max_value and substr(value,i,1) ge 'a' then max_value=substr(value,i,1);
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;If you ever have blanks in value then you need to define the result desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 16:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364636#M86503</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-06T16:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do i get values based on priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364637#M86504</link>
      <description>&lt;P&gt;Thanks for such a quick reply.. My values are in order and i have to define my priority. How can i do that ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My values are IL, IN, SA, SP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SA priority 1&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SP priority 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;IL priority 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;IN&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;priority 4&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;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jay&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 16:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364637#M86504</guid>
      <dc:creator>jb9977</dc:creator>
      <dc:date>2017-06-06T16:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do i get values based on priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364668#M86510</link>
      <description>&lt;P&gt;Your first post and last post are not consistent,&lt;/P&gt;
&lt;P&gt;In the first the values are combinations of one character, like a,b,c or d,e,f etc.&lt;/P&gt;
&lt;P&gt;while in the last are probably combinations of two characters each, like: &amp;nbsp; IL,SP,IN &amp;nbsp;- is it ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does VALUE variable always contains 3 different values?&lt;/P&gt;
&lt;P&gt;How many distinct values (like: SP or IL or IN etc.) are in your dataset?&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>Tue, 06 Jun 2017 18:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364668#M86510</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-06T18:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do i get values based on priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364671#M86512</link>
      <description>&lt;P&gt;My data is combination of two characters and i have 25 distinct values&lt;SPAN&gt; (like: SP or IL or IN etc.)&lt;/SPAN&gt; in my data set and my VALUE variable contain &amp;nbsp;5 different values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 18:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364671#M86512</guid>
      <dc:creator>jb9977</dc:creator>
      <dc:date>2017-06-06T18:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do i get values based on priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364698#M86519</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/143464"&gt;@jb9977&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for such a quick reply.. My values are in order and i have to define my priority. How can i do that ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My values are IL, IN, SA, SP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SA priority 1&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SP priority 2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;IL priority 3&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;IN&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;priority 4&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;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jay&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would use a custom format to create a new character value or an informat if I wanted a numeric:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value $priority
'SA'='1'
'SP'='2'
'IL'='3'
'IN'='4'
;
invalue priority
'SA'=1
'SP'=2
'IL'=3
'IN'=4
;
run;


data example;
   input code $;
   newchar = put(code,$priority.);
   numval = input(code,priority.);
datalines;
SA
SP
IL
IN
;
run;

&lt;/PRE&gt;
&lt;P&gt;Formats and informats are one very slick reusable way to do lookups. And if you have a data set with the current value and the new value needed you can modify that to use as input to Proc format to make formats and informats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And how to use with similar data to your previous example:&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines truncover;
  informat id best5. value $20.;
  input id  value ;
datalines;
1 SP,SA,SP
2 IL,IL,SP
3 IN,SP,IL
3 IN,IN,IL
;
run;

data want;
   set have;
   max_value= 99;
   do i = 1 to (countw(value));
     max_value = min(max_value,input(scan(value,i),priority.));
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;A 99 would mean none of the coded values you have in your list of "priority" values was in the variable Value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 19:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-get-values-based-on-priority/m-p/364698#M86519</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-06T19:37:14Z</dc:date>
    </item>
  </channel>
</rss>

