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

hi,

 

I created tables in a do loop (e.g. Table_1 to Table_30  ) and I would like to keep only one, let's say Table_13. How can I delete the other tables in a simple way?

 

thank you 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
BenbowL
Fluorite | Level 6

Hi,

 

If you wanted to make this a little more automated you could use the following:

 

data table_1 table_2 table_3 table_4 table_5 table_6;
    x=1;
run;

%let keep_table = TABLE_3;

proc sql noprint;
    select memname into :drop_tables separated by " "
    from sashelp.vcolumn 
    where libname = "WORK" and 
          memname like "TABLE_%" and
          memname ^= "&keep_table";
quit;

proc datasets;
    delete &drop_tables;
quit;

This way it doesn't matter how many datasets you create, you only need to specify the single table you want to keep (and if you have a rule for which table you want to keep you can use this to define the "keep_table" macro variable).

 

View solution in original post

5 REPLIES 5
Astounding
PROC Star

It might be possible to adjust the program so it only creates the data sets you need.  But assuming that is either not possible or not desirable, use PROC DATASETS.  This is untested, but should be easily fixable if need be:

 

proc datasets library=work;

delete table_1 - table_12;

delete table_14 - table_30;

quit;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why have you create 30 tables in the first place?  If you only want one dataset at the end, create only the one dataset, otherwise its just wasting resources and disk space.

Also, need to state the logic for why _13 should remain.  

ChrisNZ
Tourmaline | Level 20

Like this?

proc datasets lib=WORK;

  delete TAB1-TAB12 TAB14-TAB30;

quit;

  

BenbowL
Fluorite | Level 6

Hi,

 

If you wanted to make this a little more automated you could use the following:

 

data table_1 table_2 table_3 table_4 table_5 table_6;
    x=1;
run;

%let keep_table = TABLE_3;

proc sql noprint;
    select memname into :drop_tables separated by " "
    from sashelp.vcolumn 
    where libname = "WORK" and 
          memname like "TABLE_%" and
          memname ^= "&keep_table";
quit;

proc datasets;
    delete &drop_tables;
quit;

This way it doesn't matter how many datasets you create, you only need to specify the single table you want to keep (and if you have a rule for which table you want to keep you can use this to define the "keep_table" macro variable).

 

adil256
Quartz | Level 8
Sorry for late response. It's exactly what i wanted to do. It does the job perfectly.
I thought it was possible to exclude a vairable like this : var1-var10 except var3.
@RW9
I need to create the table before to retrieve the statistic from fastclus procedure. Then based on the statistic parameters, I only choose one.

Thank you guys for your quick answers. Have a good day.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 864 views
  • 0 likes
  • 5 in conversation