<?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: Determine result across multiple records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262173#M51124</link>
    <description>&lt;P&gt;Please post sample input and output data. Especially if you need help with coding.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Apr 2016 19:23:43 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-07T19:23:43Z</dc:date>
    <item>
      <title>Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262170#M51121</link>
      <description>&lt;P&gt;I am attempting to analyze patient data.&lt;BR /&gt;There are multiple visits for each patient. I want to know whether a patient had a certain result during any of their visits. For example, you go to the doctor multiple times and want to know if you were marked as overweight at any point.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 19:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262170#M51121</guid>
      <dc:creator>Elise8305</dc:creator>
      <dc:date>2016-04-07T19:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262173#M51124</link>
      <description>&lt;P&gt;Please post sample input and output data. Especially if you need help with coding.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 19:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262173#M51124</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-07T19:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262175#M51125</link>
      <description>&lt;P&gt;Here's an example of the type of coding you are likely to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=mydata;&lt;/P&gt;
&lt;P&gt;by patient;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set mydata;&lt;/P&gt;
&lt;P&gt;by patient;&lt;/P&gt;
&lt;P&gt;if first.patient then weight_condition='N';&lt;/P&gt;
&lt;P&gt;if weight &amp;gt; 300 then weight_condition='Y';&lt;/P&gt;
&lt;P&gt;if last.patient;&lt;/P&gt;
&lt;P&gt;retain weight_condition;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will end up with just one observation per patient, with the new variable(s) being part of that observation.&amp;nbsp; You can code any IF/THEN conditions you would like to assign values to new variables, but remember to add any new variables to the RETAIN statement.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 19:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262175#M51125</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-07T19:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262182#M51128</link>
      <description>&lt;P&gt;As an alternative to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;'s pseudo code build dichotomous variables valued 1/0 for yes/no for each condition of interest.&lt;/P&gt;
&lt;P&gt;A Maximum value of 1 in a summary means "yes ever told/diagnosed/whater", sum would be number of times told, mean would be percent of times told.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
   set have;
   WeightWarn = (ToldOverWeight = 'YES');
run;
Where "ToldOverWeight" is the variable in your data that has that information and ='YES' is whatever code might be there.

Proc format library=work;
value YN;
1 = 'Yes'
0 = 'No';
run;

/*And a report :*/
proc tabulate data=temp;
   class patientid;
   var WeightWarn;
   table patientid, Weightwarn='Weight Warning Status'*(max=''*f=YN. sum="Times Told Overweight"*f=best4. mean="% times told"*f=percent8.1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2016 19:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262182#M51128</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-07T19:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262197#M51133</link>
      <description>&lt;P&gt;Not knowing your data and other restrains, it is hard to script any code, As&amp;nbsp;a possible&amp;nbsp;quick &amp;amp; dirty way(suppose 300 is overweight);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select * from have 
		group by patient_id
			having sum(weight&amp;gt;=300)&amp;gt;0
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2016 20:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262197#M51133</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-04-07T20:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262214#M51138</link>
      <description>&lt;P&gt;Thank you all for your comments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the data I am considering.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id &amp;nbsp;cat &amp;nbsp;test &amp;nbsp;result &amp;nbsp;date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;chd &amp;nbsp;wgt &amp;nbsp; y &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2016&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;chd &amp;nbsp;hgt &amp;nbsp; n &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2016&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;chd &amp;nbsp;wgt &amp;nbsp; n &amp;nbsp; &amp;nbsp; &amp;nbsp;02/02/2016&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;chd &amp;nbsp;wgt &amp;nbsp; y &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2016&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;chd &amp;nbsp;wgt &amp;nbsp; y &amp;nbsp; &amp;nbsp; &amp;nbsp;01/02/2016&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;chd &amp;nbsp;hgt &amp;nbsp; n &amp;nbsp; &amp;nbsp; &amp;nbsp;01/02/2016&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to know if at any point a patient had a "y" result, regardless of the test.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does that make sense? &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 21:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262214#M51138</guid>
      <dc:creator>Elise8305</dc:creator>
      <dc:date>2016-04-07T21:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262217#M51140</link>
      <description>&lt;P&gt;Slightly more specific code, uses the format YN in my other post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   informat date mmddyy10.;
   format date mmddyy10.;
   input id $  cat $  test $ result $  date;
datalines;
1  chd  wgt   y      01/01/2016
1  chd  hgt   n      01/01/2016
1  chd  wgt   n      02/02/2016
2  chd  wgt   y      01/01/2016
2  chd  wgt   y      01/02/2016
2  chd  hgt   n      01/02/2016
;
run;

data tab; /* to build a report table from*/
   set have;
   AnyYes = (result='y');
   If test = 'wgt' then WgtYes = (result='y');
   If test = 'hgt' then HgtYes = (result='y');
   label
      AnyYes = 'Any y test result'
      WgtYes = 'Wgt test y result'
      HgtYes = 'Hgt test y result'
   ;
run;

/* and a quicky report*/
proc tabulate data=tab;
   class id;
   class test;
   var AnyYes WgtYes  HgtYes;
   table id ,
         (AnyYes WgtYes  HgtYes)* max=''*f=YN.
   ;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2016 22:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262217#M51140</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-07T22:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262253#M51163</link>
      <description>&lt;PRE&gt;
data have;
   informat date mmddyy10.;
   format date mmddyy10.;
   input id $  cat $  test $ result $  date;
datalines;
1  chd  wgt   y      01/01/2016
1  chd  hgt   n      01/01/2016
1  chd  wgt   n      02/02/2016
2  chd  wgt   y      01/01/2016
2  chd  wgt   y      01/02/2016
2  chd  hgt   n      01/02/2016
;
run;

proc sort data=have;
 by id date result;
run;
data temp;
 set have;
 by id date;
 if last.date;
run;
proc sql;
 create table want as
  select *
   from temp
    group by id
     having sum(result='y')=count(*);
quit;




&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Apr 2016 01:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262253#M51163</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-08T01:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262436#M51222</link>
      <description>Thank you everyone. I used the code from Astounding and got the output I needed. Thanks again!</description>
      <pubDate>Fri, 08 Apr 2016 14:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/262436#M51222</guid>
      <dc:creator>Elise8305</dc:creator>
      <dc:date>2016-04-08T14:03:44Z</dc:date>
    </item>
  </channel>
</rss>

