<?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: extract certain ids in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614016#M179420</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304798"&gt;@aishajennifer1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yet another option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use double DoW. It requires presorting by Subject.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = have;
by subject;
run;

data want;
   do until(last.subject);
      set have;
      by subject;
      if flag = 1 then hold = 1;
   end;
   do until(last.subject);
      set have;
      by subject;
      if hold = 1 then output;
   end;   
drop hold; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 27 Dec 2019 04:53:54 GMT</pubDate>
    <dc:creator>KachiM</dc:creator>
    <dc:date>2019-12-27T04:53:54Z</dc:date>
    <item>
      <title>extract certain ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614004#M179415</link>
      <description>&lt;P&gt;I have the following dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;subject&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;flag&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;bmi&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;23&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;23&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;23&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;25&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;25&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;25&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do: If the patient has any instance of flag = 1, I would like to pull all the data records into a diff dataset. Want:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;subject&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;flag&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;bmi&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;23&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;23&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;23&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;having = null;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really stuck.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 01:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614004#M179415</guid>
      <dc:creator>aishajennifer1</dc:creator>
      <dc:date>2019-12-27T01:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: extract certain ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614007#M179418</link>
      <description>&lt;P&gt;Below two options how to get what you want.&lt;/P&gt;
&lt;P&gt;Option 1 will change the sort order of your source data, option 2 won't.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input subject flag bmi;
  datalines;
1,1,23
1,1,23
1,,23
2,,25
2,,25
2,,25
;

/* option 1 */
title 'option 1';
proc sql;
/*  create table want as*/
    select * 
    from have 
    group by subject
    having max(flag)=1
    ;
quit;
title;

/* option 2 */
title 'option 2';
data want;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where=(flag=1))');
      h1.defineKey('subject');
      h1.defineDone();
    end;
  set have;
  if h1.check()=0 then output;
run;
proc print;
run;
title;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 02:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614007#M179418</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-12-27T02:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: extract certain ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614013#M179419</link>
      <description>&lt;P&gt;Another option. (thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;for the data step)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input subject flag bmi;
  datalines;
1,1,23
1,1,23
1,,23
2,,25
2,,25
2,,25
;

proc sort data=have(where=(flag=1)) nodupkey out=dedup(drop=bmi);
by subject;
run;

data want;
merge have(in=a) dedup(in=b);
by subject;
if a and b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 02:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614013#M179419</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-12-27T02:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: extract certain ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614016#M179420</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304798"&gt;@aishajennifer1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yet another option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use double DoW. It requires presorting by Subject.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = have;
by subject;
run;

data want;
   do until(last.subject);
      set have;
      by subject;
      if flag = 1 then hold = 1;
   end;
   do until(last.subject);
      set have;
      by subject;
      if hold = 1 then output;
   end;   
drop hold; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 04:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614016#M179420</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-12-27T04:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: extract certain ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614054#M179440</link>
      <description>&lt;PRE&gt;create table want as
select *
from have
where subject in (select subject from have where flag=1)
;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 11:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614054#M179440</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-27T11:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: extract certain ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614060#M179442</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304798"&gt;@aishajennifer1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as
	select *
	from have
	where subject in (select distinct(subject) from have where flag = 1);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 12:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614060#M179442</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-27T12:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: extract certain ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614061#M179443</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
     class id;
     var flag;
     output out=maxflag max=maxflag;
run;
data want;
     merge have maxflag;
     by id;
     if maxflag=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 12:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614061#M179443</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-27T12:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: extract certain ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614102#M179467</link>
      <description>&lt;P&gt;1. Get a list of ID's that have a 1 indicator&lt;/P&gt;
&lt;P&gt;2. Merge or filter your second data set by the list in the first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a beginner the best solution IMO would be&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 15:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-certain-ids/m-p/614102#M179467</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-12-27T15:55:25Z</dc:date>
    </item>
  </channel>
</rss>

