<?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 records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225770#M267840</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by LoanId descending Mod_Flag;
run;

data want(where=(Mod_Flag='Y' or new='N'));
set have;
by LoanId descending Mod_Flag;
retain new;
if first.LoanId then new='';
if Mod_Flag='Y' then new='Y';
if new='' then new='N';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Sep 2015 06:54:54 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2015-09-16T06:54:54Z</dc:date>
    <item>
      <title>Selecting records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225764#M267838</link>
      <description>&lt;P&gt;My data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LoanId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mod_Flag&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;12345&lt;/P&gt;&lt;P&gt;12345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;12345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;34521&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;34521&lt;/P&gt;&lt;P&gt;68749&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;68749&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;68749&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;78423&lt;/P&gt;&lt;P&gt;78423&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way that&amp;nbsp;I could select a) all records corresponding to those&amp;nbsp;LoanIds&amp;nbsp;that have a blank (ie. non-Y) mod_flag throughout the LoanId group, in addition to b)&amp;nbsp;the records from those LoanId groups whose mod_flag may either be blank or mod_flag='Y', corresponding to those LoanIds that ONLY&amp;nbsp;have a mod_flag = 'Y'? To be clearer by final data would look as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LoanId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mod_Flag&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;12345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;34521&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;34521&lt;/P&gt;&lt;P&gt;68749&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;68749&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;78423&lt;/P&gt;&lt;P&gt;78423&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 05:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225764#M267838</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2015-09-16T05:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225765#M267839</link>
      <description>&lt;P&gt;For the a) the first solution that come to my mind is to select those who have "Y"&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; by loanld mod_flag;&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;&lt;SPAN&gt;by loanld mod_flag;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;where mod_flag='Y';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if last.mod_flag; /*avoid duplicated loanld if multiple 'Y'*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;rename mod_flag=group_flag;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;merge have&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if group_flag&amp;nbsp;ne&amp;nbsp;'Y';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the b), with the original dataset have you could do something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;merge have&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if group_flag eq Mod_flag;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 06:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225765#M267839</guid>
      <dc:creator>arodriguez</dc:creator>
      <dc:date>2015-09-16T06:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225770#M267840</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by LoanId descending Mod_Flag;
run;

data want(where=(Mod_Flag='Y' or new='N'));
set have;
by LoanId descending Mod_Flag;
retain new;
if first.LoanId then new='';
if Mod_Flag='Y' then new='Y';
if new='' then new='N';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Sep 2015 06:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225770#M267840</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-09-16T06:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225803#M267841</link>
      <description>&lt;P&gt;I think a "self merge" will work nicely here.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data loan;
   infile cards firstobs=2 missover;
   input loanid :$5. mod_flag:$1.;
cards;
LoanId      Mod_Flag   
12345
12345    
12345           Y
34521     
34521
68749           Y
68749           Y
68749          
78423
78423
;;;;
   run;
proc print;
   run;
data loan2;
   merge loan loan(in=in2 rename=(mod_flag=Y) where=(Y='Y'));
   by loanid;
   if in2 and mod_flag eq 'Y' then output;
   else if not in2 then output;
   drop y;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/145i6A1E13762F4E981A/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 11:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/225803#M267841</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-09-16T11:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/226216#M267842</link>
      <description>&lt;PRE&gt;data loan;
   infile cards firstobs=2 missover;
   input loanid :$5. mod_flag:$1.;
cards;
LoanId      Mod_Flag   
12345
12345    
12345           Y
34521     
34521
68749           Y
68749           Y
68749          
78423
78423
;;;;
   run;
proc sql;
create table want as
 select * from loan group by loanid having sum(Mod_Flag='Y')=0
 union all
 select * from loan where Mod_Flag='Y'
 order by loanid;
quit;

&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2015 09:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-records/m-p/226216#M267842</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-09-18T09:28:12Z</dc:date>
    </item>
  </channel>
</rss>

