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

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,

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @pkopersk,

 

Your approach no. 2 works for me. You called the macro, didn't you?

%closevts

View solution in original post

8 REPLIES 8
Amir
PROC Star

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.

 

 

pkopersk
Fluorite | Level 6

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.

Amir
PROC Star

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.

 

FreelanceReinh
Jade | Level 19

Hello @pkopersk,

 

Your approach no. 2 works for me. You called the macro, didn't you?

%closevts
pkopersk
Fluorite | Level 6
Nope I did not!

Thank you! 🙂
FreelanceReinh
Jade | Level 19

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.

 

pkopersk
Fluorite | Level 6

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?

FreelanceReinh
Jade | Level 19

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.

 

univiewer.png

 

While you're at it, you may want to associate file type .sas with SAS.UniViewer as well. I find this quite convenient.

 

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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 5435 views
  • 5 likes
  • 3 in conversation