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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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