<?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 truncate table in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/874906#M42904</link>
    <description>&lt;P&gt;I, I would strongly recommend to NOT use the delete statement to empty a table, because it has poor performances for that... For a dataset with few records, this is fine, but as soon as you deal with thousands of records, it will take ages just to empty your dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For me, the best approach in SAS - which is also fully compatible with proc sql is the following:&lt;/P&gt;&lt;PRE&gt;create table XX like XX;&lt;/PRE&gt;&lt;P&gt;Or, for a better example:&lt;/P&gt;&lt;PRE&gt;data work.class;
  set sashelp.class;
run;

proc sql noprint;
  create table class like class;
quit;&lt;/PRE&gt;&lt;P&gt;Short and efficient!&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Wed, 10 May 2023 12:22:36 GMT</pubDate>
    <dc:creator>JuSAS</dc:creator>
    <dc:date>2023-05-10T12:22:36Z</dc:date>
    <item>
      <title>how to truncate table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/812584#M40658</link>
      <description>&lt;P&gt;How can i truncate table, this is not working for me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;BR /&gt;truncate table sasdata.barkoci;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 10:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/812584#M40658</guid>
      <dc:creator>Pato485</dc:creator>
      <dc:date>2022-05-11T10:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to truncate table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/812598#M40659</link>
      <description>&lt;P&gt;If there aren't any indexes on the table then the quickest way is to recreate it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sasdata.barkoci;
  stop;
  set  sasdata.barkoci;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sasdata.barkoci;
  set  sasdata.barkoci(obs=0);
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 11:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/812598#M40659</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-05-11T11:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to truncate table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/812608#M40662</link>
      <description>&lt;P&gt;See the following post by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;, who makes a good point about using the PROC SQL Delete approach.&lt;BR /&gt;&lt;BR /&gt;I'd go with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;approach, but if you want to use SQL:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
	do group=1 to 3 ;
		do members=1 to int(ranuni(0)*10) ;
			output ;
		end ;
	end ;
run ;

proc sql ;	
	delete * from have ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 12:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/812608#M40662</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-05-11T12:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to truncate table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/812617#M40663</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226241"&gt;@AMSAS&lt;/a&gt;&amp;nbsp;You might know already that but posting this here anyway.&lt;/P&gt;
&lt;P&gt;The issue with a SQL Delete on SAS files is that the delete is only logical. It doesn't reduce the size of the SAS file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.class;
  set sashelp.class;
run;

proc sql;
  delete from work.class;
quit;

proc contents data=work.class;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1652269754523.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71307i644BE69E73C70DF8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1652269754523.png" alt="Patrick_0-1652269754523.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you really want to mimic a SQL Truncate also maintaining all the table attributes, indexes and constraints then you have to do something "ugly" as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.class(index=(name));
  set sashelp.class;
run;

%let sv_obs=%sysfunc(getoption(obs,keyword));
%let sv_dlcreatedir=%sysfunc(getoption(dlcreatedir));
options obs=0 dlcreatedir;
libname tmp_work "%sysfunc(pathname(work))/tmp_work";
proc datasets lib=work nolist;
  copy
    in=work
    out=tmp_work
    clone
    datecopy
    force
    index=yes
    constraint=yes
    ;
  select class;
  run;
  delete class;
  run;
  copy
    in=tmp_work
    out=work
    move
    ;
  select class;
  run;
quit;

/* restore options */
options &amp;amp;sv_obs &amp;amp;sv_dlcreatedir;
libname tmp_work clear;

proc contents data=work.class;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1652270193072.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71311iEFF0D411503F2E47/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1652270193072.png" alt="Patrick_1-1652270193072.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 11:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/812617#M40663</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-05-11T11:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to truncate table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/874906#M42904</link>
      <description>&lt;P&gt;I, I would strongly recommend to NOT use the delete statement to empty a table, because it has poor performances for that... For a dataset with few records, this is fine, but as soon as you deal with thousands of records, it will take ages just to empty your dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For me, the best approach in SAS - which is also fully compatible with proc sql is the following:&lt;/P&gt;&lt;PRE&gt;create table XX like XX;&lt;/PRE&gt;&lt;P&gt;Or, for a better example:&lt;/P&gt;&lt;PRE&gt;data work.class;
  set sashelp.class;
run;

proc sql noprint;
  create table class like class;
quit;&lt;/PRE&gt;&lt;P&gt;Short and efficient!&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 10 May 2023 12:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/874906#M42904</guid>
      <dc:creator>JuSAS</dc:creator>
      <dc:date>2023-05-10T12:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to truncate table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/874916#M42905</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/313523"&gt;@Pato485&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How can i truncate table, this is not working for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;BR /&gt;truncate table sasdata.barkoci;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't.&lt;/P&gt;
&lt;P&gt;That is for database systems where making a new table is major Pain In The A** .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 12:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-truncate-table/m-p/874916#M42905</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-10T12:50:30Z</dc:date>
    </item>
  </channel>
</rss>

