<?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: find record in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234947#M54985</link>
    <description>&lt;P&gt;Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are situations where you wouldn't want to sort a data set ... size of the data set, existence of indices. &amp;nbsp;But even without good reason, the world of SAS provides many sources of incredible situations. &amp;nbsp;Here are just a few I have either encountered or heard about from others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One supervisor would not allow a MERGE statement, forcing programmers to use IF/THEN instead. &amp;nbsp;MERGE is just too difficult to master.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Student comments and questions ... well real life is stranger than you could imagine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x=2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Student question: &amp;nbsp;Why would you want to do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a = b + c;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Student comment/question: &amp;nbsp;You can't add letters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes students even produce code that works (or at least generates no errors) but is suitable for a puzzle:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if a = 1 or 2 then b=3 and c=4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS, as in real life, the truth can be stranger than fiction.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Nov 2015 23:52:52 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-11-16T23:52:52Z</dc:date>
    <item>
      <title>find record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234882#M54980</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;From the below data, how to get first record based on pid and disease. (should work only on pid with duplicate disease condition)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data abc;&lt;BR /&gt;input pid age disease $ country $ sno;&lt;BR /&gt;cards;&lt;BR /&gt;101 23 sarcoma US 1&lt;BR /&gt;101 23 sarcoma US 2&lt;BR /&gt;102 43 pneumonia China 1&lt;BR /&gt;103 56 syphilis Russia 2&lt;BR /&gt;103 52 syphilis Russia 1&lt;BR /&gt;103 57 Cpox Russia 3&lt;BR /&gt;103 58 Cpox Russia 4&lt;BR /&gt;103 59 Cpox Russia 5&lt;BR /&gt;103 59 Rpox Russia 6&lt;BR /&gt;104 75 Spox Uzbek 1&lt;BR /&gt;104 82 Spox Uzbek 2&lt;BR /&gt;104 12 Asthma Uzbek 3&lt;BR /&gt;104 13 Asthma Uzbek 4&lt;BR /&gt;104 14 Asthma Uzbek 5&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;TABLE width="320"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;pid&lt;/TD&gt;
&lt;TD width="64"&gt;age&lt;/TD&gt;
&lt;TD width="64"&gt;disease&lt;/TD&gt;
&lt;TD width="64"&gt;country&lt;/TD&gt;
&lt;TD width="64"&gt;sno&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;101&lt;/TD&gt;
&lt;TD width="64"&gt;23&lt;/TD&gt;
&lt;TD width="64"&gt;sarcoma&lt;/TD&gt;
&lt;TD width="64"&gt;US&lt;/TD&gt;
&lt;TD width="64"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;103&lt;/TD&gt;
&lt;TD width="64"&gt;52&lt;/TD&gt;
&lt;TD width="64"&gt;syphilis&lt;/TD&gt;
&lt;TD width="64"&gt;Russia&lt;/TD&gt;
&lt;TD width="64"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;103&lt;/TD&gt;
&lt;TD width="64"&gt;57&lt;/TD&gt;
&lt;TD width="64"&gt;Cpox&lt;/TD&gt;
&lt;TD width="64"&gt;Russia&lt;/TD&gt;
&lt;TD width="64"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;104&lt;/TD&gt;
&lt;TD width="64"&gt;75&lt;/TD&gt;
&lt;TD width="64"&gt;Spox&lt;/TD&gt;
&lt;TD width="64"&gt;Uzbek&lt;/TD&gt;
&lt;TD width="64"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;104&lt;/TD&gt;
&lt;TD width="64"&gt;12&lt;/TD&gt;
&lt;TD width="64"&gt;Asthma&lt;/TD&gt;
&lt;TD width="64"&gt;Uzbek&lt;/TD&gt;
&lt;TD width="64"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 16 Nov 2015 16:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234882#M54980</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2015-11-16T16:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: find record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234884#M54981</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=abc;
    by pid disease;
run;
data abc2;
    set abc;
    by pid disease;
    if first.disease;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Nov 2015 16:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234884#M54981</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-11-16T16:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: find record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234888#M54982</link>
      <description>&lt;P&gt;If you are allowed to sort your data, that would be the safest beginning:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by pid disease sno;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After that, you could continue:&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 pid disease;&lt;/P&gt;
&lt;P&gt;if first.disease=1 and last.disease=0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are not allowed to sort your data, you have to assume that they are properly grouped (all records for the same pid/disease appear together, in order).&amp;nbsp; You could then code:&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 pid disease notsorted;&lt;/P&gt;
&lt;P&gt;if first.disease=1 and last.disease=0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the result is safer if you are allowed to sort.&amp;nbsp; But it's still obtainable if you can't sort, as long as the data behave.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 17:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234888#M54982</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-11-16T17:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: find record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234892#M54983</link>
      <description>&lt;P&gt;I have never heard of a situation where you are not allowed to sort your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does that actually happen? For what reasons would you not be allowed to sort your data?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 17:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234892#M54983</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-11-16T17:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: find record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234947#M54985</link>
      <description>&lt;P&gt;Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are situations where you wouldn't want to sort a data set ... size of the data set, existence of indices. &amp;nbsp;But even without good reason, the world of SAS provides many sources of incredible situations. &amp;nbsp;Here are just a few I have either encountered or heard about from others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One supervisor would not allow a MERGE statement, forcing programmers to use IF/THEN instead. &amp;nbsp;MERGE is just too difficult to master.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Student comments and questions ... well real life is stranger than you could imagine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x=2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Student question: &amp;nbsp;Why would you want to do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a = b + c;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Student comment/question: &amp;nbsp;You can't add letters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes students even produce code that works (or at least generates no errors) but is suitable for a puzzle:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if a = 1 or 2 then b=3 and c=4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS, as in real life, the truth can be stranger than fiction.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 23:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234947#M54985</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-11-16T23:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: find record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234952#M54987</link>
      <description>&lt;P&gt;To complement&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;'s ideas, if your records a&lt;SPAN&gt;re properly grouped (all records for the same pid/disease appear together) but not always in order, you could do:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.disease);
    set abc; by pid disease notsorted;
    firstSno = min(firstSno, sno);
    end;
/* To skip groups with a single record */
if first.disease then call missing(firstSno);
do until(last.disease);
    set abc;  by pid disease notsorted;
    if sno = firstSno then do;
        output;
        /* To get only the first record of ties */
        call missing(firstSno);
        end;
    end;
drop firstSno;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Nov 2015 02:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/find-record/m-p/234952#M54987</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-17T02:34:03Z</dc:date>
    </item>
  </channel>
</rss>

