DATA Step, Macro, Functions and more

Reg:Deleting the obs (Any Tuncate in SAS)

Reply
Frequent Contributor
Posts: 140

Reg:Deleting the obs (Any Tuncate in SAS)

deleteing the obs

Hi I am having 5 crores obs obs with 80 variables i want to delete the obs.I have tryed
delete * from but it was taking more time.


I have tryed

data want;
set want(obs=0);
run;

it works but is there any alternate to delete the obs from the table at once
as truncate table.

Is there any thing like truncate table in sas

Super User
Posts: 9,681

Reg:Deleting the obs (Any Tuncate in SAS)

Did you want to create a null table without any one obs?

proc sql;

create table want like sashelp.class;

quit;

Ksharp

Frequent Contributor
Posts: 140

Reg:Deleting the obs (Any Tuncate in SAS)

No Actually is there any thing to delete all the observations in a table .in a tabale i am having 5 crores of data

so i want to delete them at once how can i do .

Trusted Advisor
Posts: 1,300

Reg:Deleting the obs (Any Tuncate in SAS)

So, you want to delete all 50 million rows from the dataset, leaving the same dataset containing no rows?

data foo;

input foo;

cards;

0

1

2

3

4

5

;

run;

proc sql;

create table foo like foo;

quit;

Super Contributor
Posts: 1,636

Re: Reg:Deleting the obs (Any Tuncate in SAS)

data foo;

if _n_=0 then set foo;

stop;

run;

Linlin

Respected Advisor
Posts: 3,892

Re: Reg:Deleting the obs (Any Tuncate in SAS)

Your data step code looks o.k. to me. You could also code it like:

data want;
stop;

set want;
run;

The SQL delete * takes more time because it's actually not truncating the table but only marking rows for deletion - so it has to process all rows AND the table keeps its size.

Super User
Posts: 9,681

Re: Reg:Deleting the obs (Any Tuncate in SAS)

As Patrick said. It will waste you lots of time.

But there is another statement to delete all obs in a table.

data class;
 set sashelp.class;
 label sex='gender';
 format weight dollar12.;
run;

proc sql;
 delete * from class;
quit;

Ksharp

Ask a Question
Discussion stats
  • 6 replies
  • 659 views
  • 3 likes
  • 5 in conversation