# Closing all tables

#### eventhestars

##### New Member
Hey everyone,
being a sloppy and unqualified SAS-user I sometimes open tables I created (VIEWTABLE) and then forget closing them before running my program again, which causes an error of course. Is there a command I could put at the beginning of my programs that closes all tables that are open?
I googled this, and could not find an answer, so sorry if this is a stupid question!
ets

#### Dason

Code:
%macro closetables;
%local i;
%do i=1 %to 20;
dm 'next VIEWTABLE:; end;';
%end;
%mend;

%closetables;
This creates a macro called closetables. If you have 20 or less tables that you are viewing it will close them all. I don't know a way to get a count of how many tables are currently open otherwise we could put that in. But if you stick this at the top of your file then it will close up to 20 tables for you.