<?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: don't know what function to use in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582763#M165821</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281903"&gt;@Rcrowder&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming I understand your requirement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Kit Subject Visit $;
datalines;
22 01 V1
22 01 V2
44 02 V1
45 02 V2
;

proc sql;
create table want as
select *,count( distinct kit)&amp;gt;1 as Flag
from have
group by subject;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Aug 2019 13:21:04 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-08-21T13:21:04Z</dc:date>
    <item>
      <title>don't know what function to use</title>
      <link>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582757#M165818</link>
      <description>&lt;P&gt;I'm writing code to flag data.&amp;nbsp; In this one dataset, we have medical kits supplied to different subjects. each subject comes in somewhere between 1 to 8 times, and each visit is labeled as V1-V8. i need to make sure that the id number on a medical kit given to a subject on his last visit, matches the same one he received on his prior visits.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ex:&lt;/P&gt;&lt;P&gt;Kit#&amp;nbsp; &amp;nbsp; &amp;nbsp;Subject&amp;nbsp; &amp;nbsp; &amp;nbsp;Visit&lt;/P&gt;&lt;P&gt;22&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;V1&lt;/P&gt;&lt;P&gt;22&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V2&lt;/P&gt;&lt;P&gt;44&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V1&lt;/P&gt;&lt;P&gt;45&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in the example, subject one would be fine, because they were given the same medical kit.&lt;/P&gt;&lt;P&gt;Subject 2 would flag, because they were given a different medical kit than in previous visits.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 13:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582757#M165818</guid>
      <dc:creator>Rcrowder</dc:creator>
      <dc:date>2019-08-21T13:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: don't know what function to use</title>
      <link>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582759#M165819</link>
      <description>&lt;P&gt;Welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Kit Subject Visit $;
datalines;
22 01 V1
22 01 V2
44 02 V1
45 02 V2
;

data want(drop=_:);
    do _iorc_=1 by 1 until (last.Subject);
        set have;
        by Subject;
        if _iorc_=1 then _Kit=Kit;
        flag=max(ifn(_Kit=Kit, 0, 1), flag);
    end;
    do until (last.Subject);
        set have;
        by Subject;  
        output; 
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Aug 2019 13:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582759#M165819</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-21T13:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: don't know what function to use</title>
      <link>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582763#M165821</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281903"&gt;@Rcrowder&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming I understand your requirement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Kit Subject Visit $;
datalines;
22 01 V1
22 01 V2
44 02 V1
45 02 V2
;

proc sql;
create table want as
select *,count( distinct kit)&amp;gt;1 as Flag
from have
group by subject;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Aug 2019 13:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582763#M165821</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-21T13:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: don't know what function to use</title>
      <link>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582768#M165825</link>
      <description>&lt;P&gt;Start by putting things in order (in case they're not already):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by subject visit;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can compare to the previous observation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by subject;
retain flag;
if first.subject then flag = 0;
if lag(kit_number) ne kit_number and not first.subject then flag = 1;
if last.subject and flag then output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Aug 2019 13:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582768#M165825</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-21T13:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: don't know what function to use</title>
      <link>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582769#M165826</link>
      <description>This works great. thank you&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Aug 2019 13:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/don-t-know-what-function-to-use/m-p/582769#M165826</guid>
      <dc:creator>Rcrowder</dc:creator>
      <dc:date>2019-08-21T13:34:31Z</dc:date>
    </item>
  </channel>
</rss>

