BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mohamed_zaki
Barite | Level 11

How to delete every observation in each dataset in a specific lib.

PROC DELETE delete all the data set, what  i need is to delete all the data set observations not the data sets it self.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Sure .Easy.

data class;set sashelp.class;run;
data cars;set sashelp.cars;run;

data _null_;
 set sashelp.vmember(where=(libname='WORK' and memtype='DATA')) end=last;
 if _n_ eq 1 then call execute('proc sql;');
 call execute(cat('create table _',trim(memname),' like ',trim(memname),';'));
 if last then call execute('quit;');
run;

Xia Keshan

View solution in original post

6 REPLIES 6
data_null__
Jade | Level 19
data class1 class2;
   set sashelp.class;
   run;

*Keep the data set but delete the obs;
data class1;
   modify class1;
   remove;
  
run;
proc contents data=class1;
   *reports 0 obs and 19 deleted obs;
  
run;



*Create the data set new with 0 obs;
data class2;
   stop;
  
set class2;
   run;
proc contents data=class2;
   *reports 0 obs and 0 deleted obs;
  
run;

Ksharp
Super User

Here are two ways :

data class;

set sashelp.class;

stop;

run;

proc sql;

create table class like sashelp.class ;

quit;

Xia Keshan

mohamed_zaki
Barite | Level 11

What if the data sets have different names not a series like class1 , class2 ......

and i do not know there names in advance_ the data sets i mean_, all what i know is the lib name

Ksharp
Super User

Sure .Easy.

data class;set sashelp.class;run;
data cars;set sashelp.cars;run;

data _null_;
 set sashelp.vmember(where=(libname='WORK' and memtype='DATA')) end=last;
 if _n_ eq 1 then call execute('proc sql;');
 call execute(cat('create table _',trim(memname),' like ',trim(memname),';'));
 if last then call execute('quit;');
run;

Xia Keshan

JLlano
Calcite | Level 5

Sorry, but I can´t agree.

 

Both solutions create a new table with the structure of another one.

 

This code does delete records from a data set:

 

Data Lib.Table;

    Set Lib.Table;

    Stop;

run;

 

Similar but not the same;

 

Regards

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 7938 views
  • 8 likes
  • 5 in conversation