<?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: Subsetting identical observations that differ by one variable in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321024#M9227</link>
    <description>&lt;P&gt;Thank you Jagadishkatam,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here are my two different scenarios:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
        INPUT orderno test $ viralresult $;
        DATALINES;
              1033730189  Respiratory Virus Panel PCR  negative
              1033730189  Respiratory Virus Panel PCR  positive
              1126522178  Respiratory Virus Panel PCR  inconclusive
              1126522178  Respiratory Virus Panel PCR  negative
              ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1) If the test results are both negative and positive then I&amp;nbsp;want to keep the positive one.&lt;/P&gt;&lt;P&gt;2) If the results are both inconclusive and negative, I want to keep the inconclusive one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on your suggestion I would only be able to retain the positive observation in scenario 1 and the negative observation in scenario 2 right?&lt;/P&gt;</description>
    <pubDate>Sat, 24 Dec 2016 04:45:43 GMT</pubDate>
    <dc:creator>Doyinsola</dc:creator>
    <dc:date>2016-12-24T04:45:43Z</dc:date>
    <item>
      <title>Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321015#M9224</link>
      <description>&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like the attached screenshot. I have observations that have identical values by some variables but differ by another variable "viralresult". For example, the "order number" and "test type" have the same values but the viral test results are different (see attached screenshot). I'm trying to keep only one observation for each order number and test type, based on the test result variable (e.g. keep one of&amp;nbsp;orderno:&lt;SPAN&gt;1033730189&lt;/SPAN&gt;, test: Respiratory Virus Panel PCR that has a positive test result). I am using SAS University Edition (&lt;SPAN&gt;Version: university.cny.sas.com@sas:university-3p.2/3p.2.f23fd5825fb4-1-1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope you can help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13283i64D20019AC6E59A2/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Screen Shot 2016-12-23 at 8.51.33 PM.png" title="Screen Shot 2016-12-23 at 8.51.33 PM.png" /&gt;</description>
      <pubDate>Sat, 24 Dec 2016 02:21:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321015#M9224</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2016-12-24T02:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321016#M9225</link>
      <description>&lt;P&gt;Please post data as text, preferable as a data step that can be used to recreate it. &amp;nbsp;I cannot copy and paste a photograph of your data into my program editor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Dec 2016 03:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321016#M9225</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-24T03:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321017#M9226</link>
      <description>&lt;P&gt;Consider that the data is sorted by orderno test viralresult. Then i use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by orderno test viralresult;&lt;/P&gt;
&lt;P&gt;if last.test;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Dec 2016 03:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321017#M9226</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-12-24T03:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321024#M9227</link>
      <description>&lt;P&gt;Thank you Jagadishkatam,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here are my two different scenarios:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
        INPUT orderno test $ viralresult $;
        DATALINES;
              1033730189  Respiratory Virus Panel PCR  negative
              1033730189  Respiratory Virus Panel PCR  positive
              1126522178  Respiratory Virus Panel PCR  inconclusive
              1126522178  Respiratory Virus Panel PCR  negative
              ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1) If the test results are both negative and positive then I&amp;nbsp;want to keep the positive one.&lt;/P&gt;&lt;P&gt;2) If the results are both inconclusive and negative, I want to keep the inconclusive one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on your suggestion I would only be able to retain the positive observation in scenario 1 and the negative observation in scenario 2 right?&lt;/P&gt;</description>
      <pubDate>Sat, 24 Dec 2016 04:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321024#M9227</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2016-12-24T04:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321025#M9228</link>
      <description>&lt;P&gt;Thank you Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here are my two different scenarios:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
        INPUT orderno  test  $ viralresult $;
        DATALINES;
              1033730189  Respiratory Virus Panel PCR  negative
              1033730189  Respiratory Virus Panel PCR  positive
              1126522178  Respiratory Virus Panel PCR  inconclusive
              1126522178  Respiratory Virus Panel PCR  negative
              ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1) If the test results are both negative and positive then I&amp;nbsp;want to keep the positive one.&lt;/P&gt;&lt;P&gt;2) If the results are both inconclusive and negative, I want to keep the inconclusive one.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Dec 2016 04:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321025#M9228</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2016-12-24T04:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321036#M9230</link>
      <description>&lt;P&gt;If your preffered order of viralresult, low to high, has just those 3 options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;inconclusive - negative - positive&lt;/P&gt;
&lt;P&gt;then, that is same order as the alphanumeric sort:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;proc sort data=have; by orderno test viralresult;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;data want; set have; by orderno test; if last.test; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if there are more result options then you need assign a prefference code to each viralresult&lt;/P&gt;
&lt;P&gt;and select by that code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Dec 2016 07:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321036#M9230</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-24T07:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321038#M9231</link>
      <description>&lt;P&gt;I also wanted to check what if the test result is inconclusive and positive. As per my assumption you will consider the positive record. But would like to check.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;consider that your order of preference is positive followed by inconclusive and last negative. In this case you need to derive a numeric code with the preferred order with proc format like below then I sort the data by code and use first.test to get the expected result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;invalue $ord&lt;/P&gt;
&lt;P&gt;'positive'=1&lt;/P&gt;
&lt;P&gt;'inconclusive'=2&lt;/P&gt;
&lt;P&gt;'negative'=3;&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 have;&lt;/P&gt;
&lt;P&gt;code=input(viralresult,$ord.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;/P&gt;
&lt;P&gt;by orderno test code;&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 have;&lt;/P&gt;
&lt;P&gt;by orderno test code;&lt;/P&gt;
&lt;P&gt;if first.test;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 03:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321038#M9231</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-12-25T03:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321067#M9232</link>
      <description>&lt;P&gt;Yes, that is typically the order of preference but for some reasone I can't get the code to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This portion of the code gives the following error:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
	Set want;
	Code = input (viralresult, best.);
Run;

 NOTE: Invalid argument to function INPUT at line 58 column 9.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I circumvented this and assign the preferred numeric code a different way. Following this, I ran the next portion of the code (using If first.test;) and obtained an empty dataset with no observations.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 03:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321067#M9232</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2016-12-25T03:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321068#M9233</link>
      <description>&lt;P&gt;This would work, but for the fact that I prefer "positive" over "inconclusive" so it will no longer follow the natural alphanumeric ordering.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 03:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321068#M9233</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2016-12-25T03:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321071#M9234</link>
      <description>sorry but you are supposed to use the informat $ord. and create the code variable and then sort the data by code like below&lt;BR /&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;invalue $ord&lt;BR /&gt;'positive'=1&lt;BR /&gt;'inconclusive'=2&lt;BR /&gt;'negative'=3;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;code=input(viralresult,$ord.);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=want;&lt;BR /&gt;by orderno test code;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by orderno test code;&lt;BR /&gt;if first.test;&lt;BR /&gt;run;</description>
      <pubDate>Sun, 25 Dec 2016 05:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321071#M9234</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-12-25T05:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321072#M9235</link>
      <description>&lt;P&gt;Thanks Jag,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final portion of the code below returns an empty dataset though.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
	Set have;
	If first.test;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Dec 2016 05:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321072#M9235</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2016-12-25T05:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321073#M9236</link>
      <description>yes it will return empty dataset, when you are using the first. then you are supposed to use the by statement, but you did not mention the by statement.&lt;BR /&gt;&lt;BR /&gt;please try this code&lt;BR /&gt;&lt;BR /&gt;proc sort data=want;&lt;BR /&gt;by orderno test code;&lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by orderno test code;&lt;BR /&gt;if first.test;&lt;BR /&gt;run;</description>
      <pubDate>Sun, 25 Dec 2016 05:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321073#M9236</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-12-25T05:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting identical observations that differ by one variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321098#M9237</link>
      <description>Perfect! Thank you for your help, it worked just fine.</description>
      <pubDate>Sun, 25 Dec 2016 17:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Subsetting-identical-observations-that-differ-by-one-variable/m-p/321098#M9237</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2016-12-25T17:03:43Z</dc:date>
    </item>
  </channel>
</rss>

