<?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 DATA DELETE Versus SQL DELETE? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687085#M208576</link>
    <description>&lt;P&gt;The following &lt;CODE&gt;have&lt;/CODE&gt; has 50000 observations. The &lt;CODE&gt;data&lt;/CODE&gt; step &lt;CODE&gt;delete&lt;/CODE&gt;s the second half of &lt;CODE&gt;have&lt;/CODE&gt;, so the last &lt;CODE&gt;sql&lt;/CODE&gt; returns 25000.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do i=1 to 50000;
output;
end;
run;

data have;
set have;
if i&amp;gt;25000 then delete;
run;

proc sql;
select nobs from dictionary.tables where libname="WORK" and memname="HAVE";
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The following &lt;CODE&gt;have&lt;/CODE&gt; identically has 50000 observations. The second &lt;CODE&gt;sql&lt;/CODE&gt; identically &lt;CODE&gt;delete&lt;/CODE&gt;s the second half of &lt;CODE&gt;have&lt;/CODE&gt;, but the third &lt;CODE&gt;sql&lt;/CODE&gt; still returns 50000.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do i=1 to 50000;
output;
end;
run;

proc sql;
delete from have where i&amp;gt;25000;
quit;

proc sql;
select nobs from dictionary.tables where libname="WORK" and memname="HAVE";
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have never thought about the second possibility because I don't &lt;CODE&gt;delete&lt;/CODE&gt; observations using &lt;CODE&gt;sql&lt;/CODE&gt;. I found this issue from the advanced programming sample questions—the &lt;CODE&gt;nobs&lt;/CODE&gt; and &lt;CODE&gt;nlobs&lt;/CODE&gt; of &lt;CODE&gt;dictionary.columns&lt;/CODE&gt; are different. How are the &lt;CODE&gt;data delete&lt;/CODE&gt; and &lt;CODE&gt;sql delete&lt;/CODE&gt; different? Why does SAS distinguish these two &lt;CODE&gt;delete&lt;/CODE&gt;s?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 01:33:26 GMT</pubDate>
    <dc:creator>Junyong</dc:creator>
    <dc:date>2020-09-28T01:33:26Z</dc:date>
    <item>
      <title>DATA DELETE Versus SQL DELETE?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687085#M208576</link>
      <description>&lt;P&gt;The following &lt;CODE&gt;have&lt;/CODE&gt; has 50000 observations. The &lt;CODE&gt;data&lt;/CODE&gt; step &lt;CODE&gt;delete&lt;/CODE&gt;s the second half of &lt;CODE&gt;have&lt;/CODE&gt;, so the last &lt;CODE&gt;sql&lt;/CODE&gt; returns 25000.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do i=1 to 50000;
output;
end;
run;

data have;
set have;
if i&amp;gt;25000 then delete;
run;

proc sql;
select nobs from dictionary.tables where libname="WORK" and memname="HAVE";
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The following &lt;CODE&gt;have&lt;/CODE&gt; identically has 50000 observations. The second &lt;CODE&gt;sql&lt;/CODE&gt; identically &lt;CODE&gt;delete&lt;/CODE&gt;s the second half of &lt;CODE&gt;have&lt;/CODE&gt;, but the third &lt;CODE&gt;sql&lt;/CODE&gt; still returns 50000.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do i=1 to 50000;
output;
end;
run;

proc sql;
delete from have where i&amp;gt;25000;
quit;

proc sql;
select nobs from dictionary.tables where libname="WORK" and memname="HAVE";
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have never thought about the second possibility because I don't &lt;CODE&gt;delete&lt;/CODE&gt; observations using &lt;CODE&gt;sql&lt;/CODE&gt;. I found this issue from the advanced programming sample questions—the &lt;CODE&gt;nobs&lt;/CODE&gt; and &lt;CODE&gt;nlobs&lt;/CODE&gt; of &lt;CODE&gt;dictionary.columns&lt;/CODE&gt; are different. How are the &lt;CODE&gt;data delete&lt;/CODE&gt; and &lt;CODE&gt;sql delete&lt;/CODE&gt; different? Why does SAS distinguish these two &lt;CODE&gt;delete&lt;/CODE&gt;s?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 01:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687085#M208576</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-09-28T01:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: DATA DELETE Versus SQL DELETE?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687124#M208578</link>
      <description>&lt;P&gt;In the first case you are overwriting the data set.&lt;/P&gt;
&lt;P&gt;In the last two cases you keep the data set and you flag some observations as deleted, but the physical number of observations is unchanged.&lt;/P&gt;
&lt;P&gt;Look at the log messages to see that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T1 T2 T3;
  do I=1 to 50000;
    output;
  end;
run;
     
data T1;
  set T1;
  if I &amp;gt; 25000 then delete;
run;

data T2;
  modify T2;
  if I &amp;gt; 25000 then delete;
run;

proc sql;
  delete from T3 where I &amp;gt; 25000;
quit;

data _null_;
  set T1 nobs=N1;
  set T2 nobs=N2;
  set T3 nobs=N3;
  putlog N1= N2= N3=;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;NOTE: The data set WORK.T1 has 25000 observations and 1 variables.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;NOTE: The data set WORK.T2 has been updated. There were 25000 observations rewritten, 0 observations added and 0 observations&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier" size="2"&gt;deleted.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;NOTE: 25000 rows were deleted from WORK.T3.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;N1=25000 N2=50000 N3=50000&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 03:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687124#M208578</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-28T03:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: DATA DELETE Versus SQL DELETE?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687125#M208579</link>
      <description>&lt;P&gt;Thanks for these details. Then, (1) what is the advantage of the &lt;CODE&gt;modify delete&lt;/CODE&gt; and the &lt;CODE&gt;sql delete&lt;/CODE&gt; over the &lt;CODE&gt;set delete&lt;/CODE&gt;? It seems they are still occupying the space so there is no storage benefit. Why do we need these? (2) Can a user countermand the &lt;CODE&gt;modify delete&lt;/CODE&gt; or the &lt;CODE&gt;sql delete&lt;/CODE&gt; to rescue the observations seemingly deleted?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 03:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687125#M208579</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-09-28T03:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: DATA DELETE Versus SQL DELETE?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687126#M208580</link>
      <description>&lt;P&gt;If you delete one row in a 10-billion-row table, you might want to avoid rewriting the table.&lt;/P&gt;
&lt;P&gt;It's a matter of balance: waste due to rewriting vs waste due to unused space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think the rows can be un-deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 03:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687126#M208580</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-28T03:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: DATA DELETE Versus SQL DELETE?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687128#M208581</link>
      <description>&lt;P&gt;Actually my example is misleading. Apologies about this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T2;
  modify T2;
  if I &amp;gt; 20000 then delete;
run;

data T2;
  modify T2;
  if I &amp;gt; 20000 then remove;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first data step does nothing. The delete statement just stops the processing of the step for the flagged observations.&lt;/P&gt;
&lt;P&gt;The second data step flags the rows as deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;NOTE: The data set WORK.T2 has been updated. There were &lt;FONT color="#FF0000"&gt;20000 &lt;/FONT&gt;observations rewritten, 0 observations added and 0 observations &lt;/FONT&gt;&lt;FONT face="courier new,courier" size="2"&gt;deleted.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;NOTE: The data set WORK.T2 has been updated. There were 0 observations rewritten, 0 observations added and &lt;FONT color="#FF0000"&gt;30000 &lt;/FONT&gt;observations &lt;/FONT&gt;&lt;FONT face="courier new,courier" size="2"&gt;deleted.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 03:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-DELETE-Versus-SQL-DELETE/m-p/687128#M208581</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-28T03:44:28Z</dc:date>
    </item>
  </channel>
</rss>

