<?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: Selecting specific subjects without samples from list in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-specific-subjects-without-samples-from-list/m-p/2181#M141</link>
    <description>data b; set a;&lt;BR /&gt;
where id=002;&lt;BR /&gt;
proc print;&lt;BR /&gt;
&lt;BR /&gt;
other&lt;BR /&gt;
&lt;BR /&gt;
data b; set a;&lt;BR /&gt;
&lt;BR /&gt;
if id=002;&lt;BR /&gt;
proc print;</description>
    <pubDate>Wed, 31 Jan 2007 17:14:54 GMT</pubDate>
    <dc:creator>jbc</dc:creator>
    <dc:date>2007-01-31T17:14:54Z</dc:date>
    <item>
      <title>Selecting specific subjects without samples from list</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-specific-subjects-without-samples-from-list/m-p/2180#M140</link>
      <description>Hi,&lt;BR /&gt;
    I have the following data:&lt;BR /&gt;
&lt;BR /&gt;
ID  Specimen&lt;BR /&gt;
001    02&lt;BR /&gt;
001    06&lt;BR /&gt;
001    05&lt;BR /&gt;
001    03&lt;BR /&gt;
001    04&lt;BR /&gt;
002    02 &lt;BR /&gt;
002    05&lt;BR /&gt;
002    06&lt;BR /&gt;
003    02&lt;BR /&gt;
003    03&lt;BR /&gt;
003    04&lt;BR /&gt;
&lt;BR /&gt;
I would like to pull out ID# 002 because they don't have specimen '03' and '04'. What is the code I use for that?&lt;BR /&gt;
&lt;BR /&gt;
Thank you!</description>
      <pubDate>Tue, 30 Jan 2007 15:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-specific-subjects-without-samples-from-list/m-p/2180#M140</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-01-30T15:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting specific subjects without samples from list</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-specific-subjects-without-samples-from-list/m-p/2181#M141</link>
      <description>data b; set a;&lt;BR /&gt;
where id=002;&lt;BR /&gt;
proc print;&lt;BR /&gt;
&lt;BR /&gt;
other&lt;BR /&gt;
&lt;BR /&gt;
data b; set a;&lt;BR /&gt;
&lt;BR /&gt;
if id=002;&lt;BR /&gt;
proc print;</description>
      <pubDate>Wed, 31 Jan 2007 17:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-specific-subjects-without-samples-from-list/m-p/2181#M141</guid>
      <dc:creator>jbc</dc:creator>
      <dc:date>2007-01-31T17:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting specific subjects without samples from list</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-specific-subjects-without-samples-from-list/m-p/2182#M142</link>
      <description>I interpreted the question a bit differently. I thought what was asked for was an &lt;B&gt;automated&lt;/B&gt;  way to output ALL the observations for ID 002, because ID 002 did NOT have specimen 3 or 4. So this is what I came up with. Of course, if they already know which ID does not have specimen 3 or 4, then the where/subsetting if is a good choice. &lt;BR /&gt;
            &lt;BR /&gt;
Basically this program shows 2 approaches in one program.&lt;BR /&gt;
 &lt;BR /&gt;
Approach 1) create a duplicate of the original file with a flag variable added that says whether a particular ID has the specimen that you're looking for; or&lt;BR /&gt;
Approach 2) split the original file into 2 files based on whether the ID has the specimen or not&lt;BR /&gt;
[pre]&lt;BR /&gt;
** first, read the data into a file;&lt;BR /&gt;
** capture the IDs that are OK ids (have the right specimens);&lt;BR /&gt;
data All_ID wantthese(keep=ID);&lt;BR /&gt;
retain wantid;&lt;BR /&gt;
  infile cards;&lt;BR /&gt;
  input ID specimen;&lt;BR /&gt;
  orig_obsno = _n_;&lt;BR /&gt;
  ** this is the condition you want to base your selection on;&lt;BR /&gt;
  if specimen in (3,4) then do;&lt;BR /&gt;
     output wantthese;&lt;BR /&gt;
  end;&lt;BR /&gt;
  ** All_ID is the SAS dataset of ALL the observations;&lt;BR /&gt;
  output All_ID;&lt;BR /&gt;
  format ID z3. specimen z2.;&lt;BR /&gt;
  return;&lt;BR /&gt;
  cards;&lt;BR /&gt;
001 02&lt;BR /&gt;
001 06&lt;BR /&gt;
001 05&lt;BR /&gt;
001 03&lt;BR /&gt;
001 04&lt;BR /&gt;
002 02 &lt;BR /&gt;
002 05&lt;BR /&gt;
002 06&lt;BR /&gt;
003 02&lt;BR /&gt;
003 03&lt;BR /&gt;
003 04&lt;BR /&gt;
  ;&lt;BR /&gt;
run;&lt;BR /&gt;
       &lt;BR /&gt;
proc sort data=All_ID;&lt;BR /&gt;
  by id;&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
** get rid of duplicates;&lt;BR /&gt;
proc sort data=wantthese out=uniqID nodupkey;&lt;BR /&gt;
  by id;&lt;BR /&gt;
run;&lt;BR /&gt;
                             &lt;BR /&gt;
** merge the 2 files together. ;&lt;BR /&gt;
** Approach 1: ;&lt;BR /&gt;
** the All_ID_flagged file will be a copy of the original file with a "flag" added;&lt;BR /&gt;
                       &lt;BR /&gt;
** Approach 2: ;&lt;BR /&gt;
** the have_3_4 file will be all the obs for IDs that HAD specimen 3 or specimen 4;&lt;BR /&gt;
** the pull_out file will be all the obs for the IDs that did NOT have specimen 3 or 4;&lt;BR /&gt;
&lt;BR /&gt;
data have_3_4 (keep= ID specimen orig_obsno)&lt;BR /&gt;
     pull_out(keep=ID specimen orig_obsno) &lt;BR /&gt;
     All_ID_flagged(keep=ID specimen flag);&lt;BR /&gt;
  length flag $45;&lt;BR /&gt;
  merge All_ID(in=Allfile) uniqID(in=got_3_4);&lt;BR /&gt;
    by id;&lt;BR /&gt;
    if Allfile = 1 then do;&lt;BR /&gt;
      if got_3_4=1 then do;&lt;BR /&gt;
	  flag = 'Yes: ID group has specimen 3 or 4';&lt;BR /&gt;
	  output All_ID_flagged have_3_4;&lt;BR /&gt;
      end;&lt;BR /&gt;
      else if got_3_4=0 then do;&lt;BR /&gt;
	  flag = 'No: ID group does NOT have specimen 3 or 4';&lt;BR /&gt;
          output All_ID_flagged pull_out;&lt;BR /&gt;
      end;&lt;BR /&gt;
    end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*** Using Approach 1 file;&lt;BR /&gt;
*** Dealing with 1 file that now has identifying flags;&lt;BR /&gt;
proc print data=ALL_ID_flagged;&lt;BR /&gt;
  title 'all the obs with their "flag" status';&lt;BR /&gt;
run;&lt;BR /&gt;
       &lt;BR /&gt;
proc print data=ALL_ID_flagged;&lt;BR /&gt;
  title 'only the obs with flag has Yes';&lt;BR /&gt;
  where flag contains 'Yes:';&lt;BR /&gt;
run;&lt;BR /&gt;
             &lt;BR /&gt;
proc print data=ALL_ID_flagged;&lt;BR /&gt;
  title 'only the obs with flag has No';&lt;BR /&gt;
  where flag contains 'No:';&lt;BR /&gt;
run;&lt;BR /&gt;
          &lt;BR /&gt;
*** Using Approach 2 files;&lt;BR /&gt;
*** Dealing with the obs that have been split into 2 groups;&lt;BR /&gt;
proc print data=have_3_4;&lt;BR /&gt;
  title 'all obs for IDs that had specimen 03 and 04        ';&lt;BR /&gt;
run;&lt;BR /&gt;
           &lt;BR /&gt;
proc print data=pull_out;&lt;BR /&gt;
  title 'Pull out all obs for IDs that did NOT have specimen 03 or 04';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 31 Jan 2007 23:16:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-specific-subjects-without-samples-from-list/m-p/2182#M142</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-01-31T23:16:48Z</dc:date>
    </item>
  </channel>
</rss>

