<?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 Selecting Observations from Repeated Measures Data in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-Observations-from-Repeated-Measures-Data/m-p/609147#M18481</link>
    <description>&lt;P&gt;I'm trying to work with the bladder dataset obtained here &lt;A href="http://support.sas.com/documentation/cdl/en/statug/66859/HTML/default/viewer.htm#statug_phreg_examples10.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/statug/66859/HTML/default/viewer.htm#statug_phreg_examples10.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As provided, the data are repeated measures with 4 observations for each subject. Each observation has a visit number from 1-4 and a binary status variable. I would like to have each subject only appear once with either the first visit where status=1&amp;nbsp;&lt;EM&gt;or&amp;nbsp;&lt;/EM&gt;if a subject never has status=1, then the last visit (visit=4). I'm thinking maybe I need to somehow use a do loop iterating over each ID, but I'm not sure how to implement. Any help is greatly appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Dec 2019 19:29:25 GMT</pubDate>
    <dc:creator>tmcwill</dc:creator>
    <dc:date>2019-12-03T19:29:25Z</dc:date>
    <item>
      <title>Selecting Observations from Repeated Measures Data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-Observations-from-Repeated-Measures-Data/m-p/609147#M18481</link>
      <description>&lt;P&gt;I'm trying to work with the bladder dataset obtained here &lt;A href="http://support.sas.com/documentation/cdl/en/statug/66859/HTML/default/viewer.htm#statug_phreg_examples10.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/statug/66859/HTML/default/viewer.htm#statug_phreg_examples10.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As provided, the data are repeated measures with 4 observations for each subject. Each observation has a visit number from 1-4 and a binary status variable. I would like to have each subject only appear once with either the first visit where status=1&amp;nbsp;&lt;EM&gt;or&amp;nbsp;&lt;/EM&gt;if a subject never has status=1, then the last visit (visit=4). I'm thinking maybe I need to somehow use a do loop iterating over each ID, but I'm not sure how to implement. Any help is greatly appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 19:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-Observations-from-Repeated-Measures-Data/m-p/609147#M18481</guid>
      <dc:creator>tmcwill</dc:creator>
      <dc:date>2019-12-03T19:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Observations from Repeated Measures Data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-Observations-from-Repeated-Measures-Data/m-p/609160#M18482</link>
      <description>&lt;P&gt;There is probably a cleaner way to do this but I think this is what you're looking for!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have(where=(status=1) in=a) have(in=b);
	by id;
	retain _outobs 0;

	if not (_outobs) and ((a and first.id) or (b and last.id)) then
		do;
			output;
			_outobs=1;
		end;

	if last.id then
		_outobs=0;
	drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Checking result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have(where=(status=1)) 
nodupkey out=check_sts;
by id;
run;

data check;
set check_sts have(where=(visit=4));
run;

proc sort data=check 
nodupkey out=check_out; 
by id; 
run;

proc compare base=want compare=check_out; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 20:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-Observations-from-Repeated-Measures-Data/m-p/609160#M18482</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-12-03T20:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Observations from Repeated Measures Data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-Observations-from-Repeated-Measures-Data/m-p/609243#M18486</link>
      <description>&lt;P&gt;Although the interleaving of two streams of HAVE data works in this case, this is not really a situation that demands two streams.&amp;nbsp; Here's an approach that uses a single stream.&amp;nbsp; The logic, of course, is effectively identical to the solution provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270457"&gt;@unison&lt;/a&gt; :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=n_status1);
  set have;
  by id;
  if first.id then n_status1=0;
  n_status1+(status=1);
  if (n_status1=1 and status=1) or
     (n_status1=0 and last.id=1) then output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 03:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-Observations-from-Repeated-Measures-Data/m-p/609243#M18486</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-04T03:16:45Z</dc:date>
    </item>
  </channel>
</rss>

