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

I was expecting someting like this:

 

proc sql;

drop table WORK.TABLETODROP_:;

quit;

 

Tables to be droped:

TABLETODROP_1

TABLETODROP_2

TABLETODROP_3

...

TABLETODROP_20

 

 

Thanks,

Ana

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @AnaC,

 

PROC DELETE can do this (not with a colon list, though):

proc delete data=TABLETODROP_1-TABLETODROP_20;
run;

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

HI @AnaC   Wow, I really like your thinking in wanting Proc SQL to be compatible with variable or dataset names lists. I'm afraid lists(shortened versions) do not work in Proc SQL. You would have to separate one by one with a comma in between. Nice try though! 🙂

 

 

Alternatively, you can write a small macro to hold that list separated by ',' and call that in the drop table clause in Proc SQL

FreelanceReinh
Jade | Level 19

Hi @AnaC,

 

PROC DELETE can do this (not with a colon list, though):

proc delete data=TABLETODROP_1-TABLETODROP_20;
run;
AnaC
Fluorite | Level 6
Thanks, it works!! Now I don't need to type all the table names.
For know I know how many table a have but some times I might have 30 or 40. My initial ideia with the ":" would be to cover this situation.
FreelanceReinh
Jade | Level 19

If the deletion is just a manual step (as opposed to a production program whose log must be clean), you can use a "large enough" end value (like 99) for the list of numeric suffixes. For each non-existing dataset in the list you will get a

WARNING: File WORK.TABLETODROP_##.DATA does not exist.

in the log, though.

 

For a clean log @Tom's suggested code using PROC DATASETS is a better solution in case of an unknown number of files to be deleted having the same prefix. With this procedure the prefix-colon abbreviation works as it does in other contexts (e.g. SET statement). And, no, it has nothing to do with dataset names containing a ":" -- colons in dataset names are always invalid, even with the option setting VALIDMEMNAME=EXTEND (see Summary of Extended Rules for Naming SAS Data Sets and SAS Variables).

AnaC
Fluorite | Level 6
So with my data names I should writ something like:
proc datasets nolist lib=work;
delete tabletodrop: ;
run;quit;
Tom
Super User Tom
Super User

Trying to get SQL to act like SAS code is probably not a useful path to follow.

I would think that PROC DELETE should allow this.

proc delete data=have: ;
run;

But it doesn't.

 

However you can use to more cumbersome PROC DATASETS instead.

proc datasets nolist lib=work;
  delete have: ;
run;quit;
AnaC
Fluorite | Level 6

A I haven't try this because it seams that is for when I have ":" in the table name and not when a have a lot of table with the same prefix. Am I understanding wrong this code?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 4631 views
  • 3 likes
  • 4 in conversation