Hello,
I want to develop a simple code to close all viewtables before running the rest of the program.
Here is what I managed to find so far:
dm 'next VIEWTABLE:; end;';
which only closes one table.
Therefore I am looking for a way to run this code many times to close all viewtables.
Here is what I have attempted so far:
1:Using a do loop in a data step (works only once then returns an error because the "end"s disturb the do block:
data _null_; do i=1 to 20; dm 'next VIEWTABLE:; end;'; end; run;
2:Using a macro statement (doesn't work) in order to have one "end" and another "%end" without confusion for the do block:
%macro closevts; %do i=1 %to 20; dm 'next VIEWTABLE:; end;'; %end; %mend;
3: putting a do loop in a datastep inside the macro statement (doesn't do anything):
%macro closevts; %do i=1 %to 20; data _null_; dm 'next VIEWTABLE:; end;'; run; %end; %mend;
Anyone can help me with this please?
Best,
Hi,
Which SAS product are you using, SAS Base?
Is there a tick box in the options window that does this for you automatically before a program runs?
There is a tick box option in SAS EG to do this.
Regards,
Amir.
Hi,
I am using SAS BASE and don't have access to SAS EG so I guess it has to be done with a script. I checked everywhere and there is no checkbox option to do that.
Hi,
In the data step you loop 20 times. Are there at least 20 data sets open? If not, reduce the loop to the number of viewtable windows.
What is the error message you see with the data step?
Regards,
Amir.
You're welcome. Don't worry, you're not the first programmer who forgot this. 🙂
I guess you want to close the Viewtables because you dislike this error message:
ERROR: You cannot open WORK.YOUR.DATA for output access with member-level control because WORK.YOUR.DATA is in use by you in resource environment ViewTable Window.
So do I and this is one reason why I prefer the SAS Universal Viewer to Viewtables. I've adjusted the settings in my Windows Explorer so that a double-click on a .sas7bdat file opens the SAS Universal Viewer with that dataset.
Hey I downloaded SAS viewer but I don't see where I can edit the setting to reproduce what you did. Can you be so kind and describe where I can do this please?
In Windows 7: Click Start button, then "Standard Programs" (this can also be accessed via Control Panel), then "Associate a file type or protocol with a program". In the long list of filename extensions scroll down and select .sas7bdat, click "Change program" button and select SAS.UniViewer (if this is not listed, click Browse and navigate to the SAS.UniViewer.exe, which may reside in C:\Program Files\SASHome\SASUniversalViewer\1.4 [or higher version number] or wherever you installed it). Confirm with OK.
While you're at it, you may want to associate file type .sas with SAS.UniViewer as well. I find this quite convenient.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.