<?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 Macro to delete observation in a dataset from another dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132919#M36141</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to delete observation from one dataset based on the observations from another &lt;/P&gt;&lt;P&gt;Ex :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="WIDTH: 257px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl67" colspan="2" height="20" width="257"&gt;Dataset1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" style="border-top: medium none;"&gt;Obs&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;Varaible1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;1&lt;/TD&gt;&lt;TD class="xl66" style="border-left: medium none; border-top: medium none;" width="193"&gt;IC006218&amp;nbsp; Y134&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;2&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;IC006219&amp;nbsp; Y158&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;3&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;IC006216&amp;nbsp; Y1340001&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="WIDTH: 125px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl66" colspan="2" height="20" style="border-right: black 0.5pt solid;" width="125"&gt;Dataset2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" style="border-top: medium none;"&gt;Obs&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;Varaible2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;1&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;Y134&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;2&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;Y134001&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here based on dataset2 observations ( in varaiable2), it must delete the entries in dataset 1. so ideally observations 1 &amp;amp; 3&amp;nbsp; must be deleted in dataset1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe this code should be looped and macro needs to be created for this. Appreciate your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any other suggestions are also welcomed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;Data dataset3&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;;&lt;/SPAN&gt; &lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;&amp;nbsp; Set dataset1&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;IF INDEXW(varaible1,"Y134") &amp;gt;0 THEN delete; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;Run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; font-size: 10pt;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; font-size: 10pt;"&gt;Hari Prasad&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Sep 2013 09:09:44 GMT</pubDate>
    <dc:creator>HariPrasad</dc:creator>
    <dc:date>2013-09-10T09:09:44Z</dc:date>
    <item>
      <title>Macro to delete observation in a dataset from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132919#M36141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to delete observation from one dataset based on the observations from another &lt;/P&gt;&lt;P&gt;Ex :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="WIDTH: 257px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl67" colspan="2" height="20" width="257"&gt;Dataset1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" style="border-top: medium none;"&gt;Obs&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;Varaible1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;1&lt;/TD&gt;&lt;TD class="xl66" style="border-left: medium none; border-top: medium none;" width="193"&gt;IC006218&amp;nbsp; Y134&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;2&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;IC006219&amp;nbsp; Y158&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;3&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;IC006216&amp;nbsp; Y1340001&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="WIDTH: 125px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl66" colspan="2" height="20" style="border-right: black 0.5pt solid;" width="125"&gt;Dataset2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" style="border-top: medium none;"&gt;Obs&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;Varaible2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;1&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;Y134&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: medium none;"&gt;2&lt;/TD&gt;&lt;TD class="xl65" style="border-left: medium none; border-top: medium none;"&gt;Y134001&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here based on dataset2 observations ( in varaiable2), it must delete the entries in dataset 1. so ideally observations 1 &amp;amp; 3&amp;nbsp; must be deleted in dataset1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe this code should be looped and macro needs to be created for this. Appreciate your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any other suggestions are also welcomed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;Data dataset3&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;;&lt;/SPAN&gt; &lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;&amp;nbsp; Set dataset1&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;IF INDEXW(varaible1,"Y134") &amp;gt;0 THEN delete; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: Arial; color: black; font-size: 14pt; font-weight: bold;"&gt;Run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; font-size: 10pt;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left; margin-top: 3.36pt; text-indent: -0.38in; padding-left: 34px;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; font-size: 10pt;"&gt;Hari Prasad&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 09:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132919#M36141</guid>
      <dc:creator>HariPrasad</dc:creator>
      <dc:date>2013-09-10T09:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to delete observation in a dataset from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132920#M36142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Quick fix using sql:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Deleting rows from dataset:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; delete from dataset1 where variable2 in (select distinct variable2 from dataset2);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to create a new dataset:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table dataset3 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select * from dataset1 where variable2 not in (select distinct variable2 from dataset2);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Fredrik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 09:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132920#M36142</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2013-09-10T09:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to delete observation in a dataset from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132921#M36143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try below code...this may help...im not executed ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;/P&gt;&lt;P&gt;input variable1 $20.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;IC006218&amp;nbsp; Y134&lt;/P&gt;&lt;P&gt;IC006219&amp;nbsp; Y158&lt;/P&gt;&lt;P&gt;IC006216&amp;nbsp; Y1340001&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select count(variable1) into :count separated by ',' from test1;&lt;/P&gt;&lt;P&gt;select variable1 into :var1 - :var&amp;amp;count. from test1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;count;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test2;&lt;/P&gt;&lt;P&gt;input variable2 $20.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;Y134&lt;/P&gt;&lt;P&gt;Y1340001&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select count(distinct(variable2)) into :count1 separated by ',' from test2;&lt;/P&gt;&lt;P&gt;select variable2 into :var_del1 - :var_del&amp;amp;count1.&amp;nbsp; from test2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;count1;&lt;/P&gt;&lt;P&gt;%put &amp;amp;var_del1 &amp;amp;var_del2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let x= 1;&lt;/P&gt;&lt;P&gt;%put &amp;amp;&amp;amp;var_del&amp;amp;x;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro want;&lt;/P&gt;&lt;P&gt;Data test3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Set test1;&lt;/P&gt;&lt;P&gt;%do i = 1 %to&amp;nbsp; &amp;amp;count.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %do j = 1 %to &amp;amp;count1.;&lt;/P&gt;&lt;P&gt;IF INDEXW(variable1,"&amp;amp;&amp;amp;var_del&amp;amp;j..") gt 0 THEN delete;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%want;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 12:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132921#M36143</guid>
      <dc:creator>yaswanthj</dc:creator>
      <dc:date>2013-09-10T12:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to delete observation in a dataset from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132922#M36144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If i understand you requirement correctly,here is the solution which is specific to your requirement .You can do manipulations to bellow code according to your requirement .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;/P&gt;&lt;P&gt;input variable2 $20.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;Y134&lt;/P&gt;&lt;P&gt;Y1340001&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select variable2 into :list separated by '","' from test1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test2;&lt;/P&gt;&lt;P&gt;input variable1 $20.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;IC006218&amp;nbsp; Y134&lt;/P&gt;&lt;P&gt;IC006219&amp;nbsp; Y158&lt;/P&gt;&lt;P&gt;IC006216&amp;nbsp; Y1340001&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Data T3;&lt;/P&gt;&lt;P&gt;set test2;&lt;/P&gt;&lt;P&gt;if scan(variable1,2) in ("&amp;amp;LIST") then delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards.&lt;/P&gt;&lt;P&gt;Sanjeev.K&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 13:11:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132922#M36144</guid>
      <dc:creator>kuridisanjeev</dc:creator>
      <dc:date>2013-09-10T13:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to delete observation in a dataset from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132923#M36145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If we does not know the position, we can not able to use scan function i guess.. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 13:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-to-delete-observation-in-a-dataset-from-another-dataset/m-p/132923#M36145</guid>
      <dc:creator>yaswanthj</dc:creator>
      <dc:date>2013-09-10T13:22:16Z</dc:date>
    </item>
  </channel>
</rss>

