<?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: how to filer a data set based on another dataset without change the order in current data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-filer-a-data-set-based-on-another-dataset-without-change/m-p/898991#M355335</link>
    <description>&lt;P&gt;You create an order variable to allow the sequence to be maintained. You filter on whether or not subject in data set HAVE is also in data set ID or subject is blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',' dsd;
input subject $ year disease1 disease2 disease3;
datalines;
a,2019,1,1,1
,2020,0,0,0
a,2021,0,0,0
a,2022,0,0,0
b,2019,0,1,1
f,2020,1,0,0
c,2021,1,0,0
w,2022,0,0,1
;

 

data id;
input subject $;
datalines;
a
b
c
d
e
f
g
;

data have1;
    set have;
    n=_n_;
run;

proc sql;
    create table want as select *
        from have1 
        where subject in (select distinct subject from id) or subject=' '
        order by n;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Oct 2023 18:36:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-10-17T18:36:16Z</dc:date>
    <item>
      <title>how to filer a data set based on another dataset without change the order in current data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-filer-a-data-set-based-on-another-dataset-without-change/m-p/898990#M355334</link>
      <description>&lt;P&gt;hello, I have two data set 'have' and 'id'. I would like to filter 'have' data based on the subject in 'id' and keep record order unchanged. What should I do?&amp;nbsp; sort and them merge will not work. also I have a record with empty 'subject' that should be retained, as ' " is in subject value in data 'id'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input subject $ year disease1 disease2 disease3;&lt;BR /&gt;datalines;&lt;BR /&gt;a 2019 1 1 1&lt;BR /&gt;2020 0 0 0&lt;BR /&gt;a 2021 0 0 0&lt;BR /&gt;a 2022 0 0 0&lt;BR /&gt;b 2019 0 1 1&lt;BR /&gt;f 2020 1 0 0&lt;BR /&gt;c 2021 1 0 0&lt;BR /&gt;w 2022 0 0 1&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data id;&lt;BR /&gt;input subject $;&lt;BR /&gt;datalines;&lt;BR /&gt;a&lt;BR /&gt;b&lt;BR /&gt;c&lt;BR /&gt;d&lt;BR /&gt;e&lt;/P&gt;&lt;P&gt;f&lt;BR /&gt;g&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 17:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-filer-a-data-set-based-on-another-dataset-without-change/m-p/898990#M355334</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2023-10-17T17:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to filer a data set based on another dataset without change the order in current data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-filer-a-data-set-based-on-another-dataset-without-change/m-p/898991#M355335</link>
      <description>&lt;P&gt;You create an order variable to allow the sequence to be maintained. You filter on whether or not subject in data set HAVE is also in data set ID or subject is blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',' dsd;
input subject $ year disease1 disease2 disease3;
datalines;
a,2019,1,1,1
,2020,0,0,0
a,2021,0,0,0
a,2022,0,0,0
b,2019,0,1,1
f,2020,1,0,0
c,2021,1,0,0
w,2022,0,0,1
;

 

data id;
input subject $;
datalines;
a
b
c
d
e
f
g
;

data have1;
    set have;
    n=_n_;
run;

proc sql;
    create table want as select *
        from have1 
        where subject in (select distinct subject from id) or subject=' '
        order by n;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 18:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-filer-a-data-set-based-on-another-dataset-without-change/m-p/898991#M355335</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-17T18:36:16Z</dc:date>
    </item>
  </channel>
</rss>

