<?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: Obtaining best response from multiple records. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754207#M237788</link>
    <description>&lt;P&gt;You request "per subject". Which variable(s) define a specific subject?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My basic approach would be to create a new variable where "best" is the greatest value, ie your current 5 is mapped to 10(or similar) and the "worst" non-missing is mapped to 1. The use a procedure like Proc means/summary or if you only need a report then Proc Report or Tabulate.&amp;nbsp; to identify the maximum value by subject. Create a format that will display the 10 back to 5 (if that is the "best").&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jul 2021 23:02:43 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-07-14T23:02:43Z</dc:date>
    <item>
      <title>Obtaining best response from multiple records.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754205#M237786</link>
      <description>&lt;P&gt;I have a dataset with multiple treatment response records. I have a order of best response which is (5, 1, 7, 2, 3, 6). I want to output the best response from the multiple records which ever comes first&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data;
input @1 SEQNO $6. @8 SEGMENT $16. @25 TreatmentResponse 1.;
cards;
May001 Treatment        .
M001   Treatment        1
M001                    1
M002   Progression       6
M012   Treatment        3
M012   Treatment        6
M012   End of Treatment .
M015   Treatment        6
M017   Treatment        7
M017   Treatment        5
M017   Treatment        1
M018   Treatment        1
M018   Treatment        5
M020   Treatment        2
M020   Treatment        6
M021   Treatment        7
M022   Treatment        2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want output single record per subject with best response (order):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;May001 Treatment        .
M001   Treatment        1
M002   Progression       6
M012   Treatment        3
M015   Treatment        6
M017   Treatment        5
M018   Treatment        5
M020   Treatment        6
M021   Treatment        7
M022   Treatment        2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 22:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754205#M237786</guid>
      <dc:creator>RAVI2000</dc:creator>
      <dc:date>2021-07-14T22:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining best response from multiple records.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754206#M237787</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format; 
   value order 5='5' 1='4' 7='3' 2='2' 3='1' 6='0' ;

proc sql;
  select *
  from HAVE
  group by SEQNO
  having put(TREATMENTRESPONSE,order.)=max(put(TREATMENTRESPONSE,order.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 22:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754206#M237787</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-14T22:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining best response from multiple records.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754207#M237788</link>
      <description>&lt;P&gt;You request "per subject". Which variable(s) define a specific subject?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My basic approach would be to create a new variable where "best" is the greatest value, ie your current 5 is mapped to 10(or similar) and the "worst" non-missing is mapped to 1. The use a procedure like Proc means/summary or if you only need a report then Proc Report or Tabulate.&amp;nbsp; to identify the maximum value by subject. Create a format that will display the 10 back to 5 (if that is the "best").&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 23:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754207#M237788</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-14T23:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining best response from multiple records.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754208#M237789</link>
      <description>&lt;P&gt;Create a separate variable with its order and then sort it. Keep the first entry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input @1 SEQNO $6. @8 SEGMENT $16. @25 TreatmentResponse 1.;
cards;
May001 Treatment        .
M001   Treatment        1
M001                    1
M002   Progression      6
M012   Treatment        3
M012   Treatment        6
M012   End of Treatment .
M015   Treatment        6
M017   Treatment        7
M017   Treatment        5
M017   Treatment        1
M018   Treatment        1
M018   Treatment        5
M020   Treatment        2
M020   Treatment        6
M021   Treatment        7
M022   Treatment        2
;
run;

data have1;
 set have;
 if TreatmentResponse=5 then temp=1;
 else if TreatmentResponse=1 then temp=2; 
 else if TreatmentResponse=7 then temp=3; 
 else if TreatmentResponse=2 then temp=4; 
 else if TreatmentResponse=3 then temp=5; 
 else if TreatmentResponse=6 then temp=6;
 else if TreatmentResponse=. then temp=99;
run;

proc sort data=have1; by SEQNO temp; run;

data output;
 set have1;
  by seqno;
  if first.seqno;
  drop temp;
run;

proc print data=output; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jul 2021 23:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-best-response-from-multiple-records/m-p/754208#M237789</guid>
      <dc:creator>Rydhm</dc:creator>
      <dc:date>2021-07-14T23:08:54Z</dc:date>
    </item>
  </channel>
</rss>

