<?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: need help with a dataset filtering of records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949532#M371417</link>
    <description>&lt;P&gt;One way is processing data in BY/GROUP&amp;nbsp; and RETAIN statement where first.variable reads the first record in the group (USUBJID here) and the last.variable reads the second/last record, retain statement carries over the first record to the next record to enable comparison.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
	infile datalines truncover; 
	input usubjid $ actarm $;
	datalines;
us222 A
us222 
us111 B
us333 C
us333 C
us444 
us444 
;
run; 


proc sort data=have; 
	by usubjid descending actarm;
run; 

data want;
	set have;
	by usubjid descending actarm;
	retain _actarm;
	if first.usubjid then _actarm=actarm;
	if last.usubjid and _actarm^=actarm then delete; 
	drop _:; 
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2024 21:56:11 GMT</pubDate>
    <dc:creator>A_Kh</dc:creator>
    <dc:date>2024-10-30T21:56:11Z</dc:date>
    <item>
      <title>need help with a dataset filtering of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949521#M371415</link>
      <description>&lt;P&gt;I have&amp;nbsp; a dataset with multiple subjects . One usubjid can have two records with different subjid. i want to filter the dataset with following rules&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Keep all single records (only one record for that &lt;CODE&gt;usubjid&lt;/CODE&gt;) automatically.&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;For groups (within &lt;CODE&gt;usubjid&lt;/CODE&gt;) with exactly two records where one record has a non-missing &lt;CODE&gt;actarm&lt;/CODE&gt; and the other is missing, keep only the record with the non-missing &lt;CODE&gt;actarm&lt;/CODE&gt;.&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;If both records have non-missing &lt;CODE&gt;actarm&lt;/CODE&gt;, keep both.&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;If both records have missing &lt;CODE&gt;actarm&lt;/CODE&gt;, keep both.&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 21:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949521#M371415</guid>
      <dc:creator>abhisas1</dc:creator>
      <dc:date>2024-10-30T21:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: need help with a dataset filtering of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949523#M371416</link>
      <description>&lt;P&gt;You want a code suggestion.&amp;nbsp; So help us help you.&amp;nbsp; Please provide sample data in the form of a DATA step, and show the corresponding desired results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, what have you tried so far?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh yes, and can your dataset have a USUBJID with MORE THAN 2 observations?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 21:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949523#M371416</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-10-30T21:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: need help with a dataset filtering of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949532#M371417</link>
      <description>&lt;P&gt;One way is processing data in BY/GROUP&amp;nbsp; and RETAIN statement where first.variable reads the first record in the group (USUBJID here) and the last.variable reads the second/last record, retain statement carries over the first record to the next record to enable comparison.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
	infile datalines truncover; 
	input usubjid $ actarm $;
	datalines;
us222 A
us222 
us111 B
us333 C
us333 C
us444 
us444 
;
run; 


proc sort data=have; 
	by usubjid descending actarm;
run; 

data want;
	set have;
	by usubjid descending actarm;
	retain _actarm;
	if first.usubjid then _actarm=actarm;
	if last.usubjid and _actarm^=actarm then delete; 
	drop _:; 
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 21:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949532#M371417</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2024-10-30T21:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: need help with a dataset filtering of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949540#M371418</link>
      <description>&lt;P&gt;You really have to seriously expand on exactly what this means:&lt;/P&gt;
&lt;PRE&gt; One usubjid can have two records with different subjid. &lt;/PRE&gt;
&lt;P&gt;As in provide examples, how if there are different values of "subjid" how we can tell from the data that they are supposed to be treated as one. You do not mention any rules for "subjid". How does that variable interact with Actarm???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356985"&gt;@abhisas1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have&amp;nbsp; a dataset with multiple subjects . One usubjid can have two records with different subjid. i want to filter the dataset with following rules&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Keep all single records (only one record for that &lt;CODE&gt;usubjid&lt;/CODE&gt;) automatically.&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;For groups (within &lt;CODE&gt;usubjid&lt;/CODE&gt;) with exactly two records where one record has a non-missing &lt;CODE&gt;actarm&lt;/CODE&gt; and the other is missing, keep only the record with the non-missing &lt;CODE&gt;actarm&lt;/CODE&gt;.&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;If both records have non-missing &lt;CODE&gt;actarm&lt;/CODE&gt;, keep both.&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;If both records have missing &lt;CODE&gt;actarm&lt;/CODE&gt;, keep both.&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 22:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949540#M371418</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-10-30T22:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: need help with a dataset filtering of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949556#M371424</link>
      <description>&lt;P&gt;What if you have more than two records for one usubjectid, what you gotta do ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
	infile datalines truncover; 
	input usubjid $ actarm $;
	datalines;
us222 A
us222 
us111 B
us333 C
us333 C
us444 
us444 
;
run; 
proc sql;
create table want as
select *
 from have 
  group by usubjid
   having actarm=max(actarm);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Oct 2024 01:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949556#M371424</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-31T01:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: need help with a dataset filtering of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949559#M371426</link>
      <description>&lt;P&gt;In addition to the questions others have asked it is probably worth considering how you got into this situation to begin with.&lt;/P&gt;
&lt;P&gt;Why is it that some of the observations have different values of ACTARM?&lt;/P&gt;
&lt;P&gt;Could you go back a step and fix the process that made this dataset so that ACTARM is populated correctly to begin with?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 02:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949559#M371426</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-31T02:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: need help with a dataset filtering of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949600#M371432</link>
      <description>&lt;P&gt;I liked&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321371"&gt;@A_Kh&lt;/a&gt;'s suggestion to sort by USUBJID &lt;EM&gt;&lt;STRONG&gt;descending&lt;/STRONG&gt;&lt;/EM&gt; ACTARM, which is intended to put missing ACTARM obs last within a USUBJID.&amp;nbsp; But without a minor edit, it would not accommodate two &lt;U&gt;&lt;STRONG&gt;distinct&lt;/STRONG&gt;&lt;/U&gt; valid values for ACTARM (if a USUBJID had a valid "B" and a valid "C", the "B" would be deleted).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this alternative, applied to data HAVE sorted by USUBJID (but not necessarily by ACTARM within USUBJID):&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=(missing(actarm)=0)  in=valid)
      have (where=(missing(actarm))   in=miss);
  by usubjid;

  if lag(valid)=1 and first.usubjid=0 and miss=1 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 16:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-a-dataset-filtering-of-records/m-p/949600#M371432</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-10-31T16:29:12Z</dc:date>
    </item>
  </channel>
</rss>

