<?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 working within the observation with the same id. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/working-within-the-observation-with-the-same-id/m-p/15010#M2570</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't post ouput you want to see. So&lt;/P&gt;&lt;P&gt;Assuming only good or bad can be 1.(i.e. good=1 bad=0&amp;nbsp;&amp;nbsp; or&amp;nbsp;&amp;nbsp; good=0&amp;nbsp; bad=1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;libname x v9 'c:\';
proc means data=x.test nway noprint;
 class id;
 var bad;
 output out=temp(drop=_type_ rename=(id=_id))&amp;nbsp; sum= /autoname;
run;
data want(drop=_: bad_sum);
 set x.test;
 retain flag ' ';
 if id ne lag(id) then do;
&amp;nbsp;&amp;nbsp; flag='N';
&amp;nbsp;&amp;nbsp; if good=1 then do;
&amp;nbsp;&amp;nbsp; do i=1 to _nobs;
&amp;nbsp;&amp;nbsp;&amp;nbsp; set temp nobs=_nobs point=i;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if id=_id and _freq_=bad_sum+1 and _freq_ ne 1 then do; flag='Y'; leave;end;
&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp; end;
 end;
run;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 Dec 2011 07:30:22 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-12-15T07:30:22Z</dc:date>
    <item>
      <title>working within the observation with the same id.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/working-within-the-observation-with-the-same-id/m-p/15009#M2569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;﻿Dear SAS users.&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am currently working with the attatched dataset called "test".&lt;/P&gt;&lt;P&gt;where the &lt;SPAN style="color: #ff0000;"&gt;&lt;EM&gt;good &lt;/EM&gt;&lt;/SPAN&gt;and &lt;SPAN style="color: #ff0000;"&gt;&lt;EM&gt;bad&lt;/EM&gt;&lt;/SPAN&gt; variables are binary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to keep ONLY the groups that&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- have a good flag in the first row&lt;/P&gt;&lt;P&gt;- have a bad flag in any row after the first row.&lt;/P&gt;&lt;P&gt;﻿﻿&lt;/P&gt;&lt;P&gt;Also assign a string as a fourth variable that would have "Y" if they satify the above crieteria or "N" otherwise.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;﻿&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 05:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/working-within-the-observation-with-the-same-id/m-p/15009#M2569</guid>
      <dc:creator>willy0625</dc:creator>
      <dc:date>2011-12-15T05:56:50Z</dc:date>
    </item>
    <item>
      <title>working within the observation with the same id.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/working-within-the-observation-with-the-same-id/m-p/15010#M2570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't post ouput you want to see. So&lt;/P&gt;&lt;P&gt;Assuming only good or bad can be 1.(i.e. good=1 bad=0&amp;nbsp;&amp;nbsp; or&amp;nbsp;&amp;nbsp; good=0&amp;nbsp; bad=1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;libname x v9 'c:\';
proc means data=x.test nway noprint;
 class id;
 var bad;
 output out=temp(drop=_type_ rename=(id=_id))&amp;nbsp; sum= /autoname;
run;
data want(drop=_: bad_sum);
 set x.test;
 retain flag ' ';
 if id ne lag(id) then do;
&amp;nbsp;&amp;nbsp; flag='N';
&amp;nbsp;&amp;nbsp; if good=1 then do;
&amp;nbsp;&amp;nbsp; do i=1 to _nobs;
&amp;nbsp;&amp;nbsp;&amp;nbsp; set temp nobs=_nobs point=i;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if id=_id and _freq_=bad_sum+1 and _freq_ ne 1 then do; flag='Y'; leave;end;
&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp; end;
 end;
run;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 07:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/working-within-the-observation-with-the-same-id/m-p/15010#M2570</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-12-15T07:30:22Z</dc:date>
    </item>
    <item>
      <title>working within the observation with the same id.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/working-within-the-observation-with-the-same-id/m-p/15011#M2571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data want(drop=one two);
 one=1; two=1;
 do until(last.id);
&amp;nbsp; set test;
&amp;nbsp; by id notsorted; 
&amp;nbsp; if first.id and good ne 1 then one=0;
&amp;nbsp; if (not first.id and bad ne 1) or (first.id and last.id) then two=0;
 end;

 if one and two then flag='Y';
&amp;nbsp;&amp;nbsp; else flag='N';

 do until(last.id);
&amp;nbsp; set test;
&amp;nbsp; by id notsorted; 
 output;
 end;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 07:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/working-within-the-observation-with-the-same-id/m-p/15011#M2571</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-12-15T07:50:36Z</dc:date>
    </item>
  </channel>
</rss>

