I just bumped into a scenario where a macro needed to write to a dataset, but the dataset was opened (in a window) and the macro threw this familiar error.
ERROR: You cannot open WORK.OUTPUT_DATASET.DATA for output access with member-level control because WORK.OUTPUT_DATASET.DATA is in use by you in resource environment ViewTable Window.
Ideally, I'd want the macro to prompt me to close the dataset (and maybe rename it) before proceeding. A 100% automated (silent) solution is not appropriate in this scenario. I'm sure I can cook up something functional, but thought I'd check with the community first in case a simple solution already exists.
Running SAS 9.4
Thanks!
Wouldn't it be an option to use SAS Universal Viewer instead of ViewTables? This is what I use and recommend to avoid this problem (see, e.g., this thread: Close all VIEWTABLES).
the one way to take care of that is to wright to a dataset with another name.
data want;
set have;
/* do a bunch of stuff */
run;
another way to take care of the problem is to make sure you close the datasets in SAS before trying to wright to them.
SAS can do a lot of things but this is a user error issue.
Thanks for the feedback.
Writing to another name would not be ideal, but could be done. I can test if the dataset is opened and dynamically create another name. This of course introduces other risks, what if that name isn't "legal" or another subsequent process is looking for the original name?
You're right though, this is a USER error I am trying to avoid!
Environment and other user behaviors will affect how likely this can be done from code.
If you are running SAS in Display Manager (not SAS studio or Enterprise Guide) then the DM command lets you send commands to SAS.
In which case this may work:
dm "next viewtable:work.output_dataset ;end;";
The NEXT command needs to know the name of a window or it will likely access the wrong one. The End closes the window. You need a ; between commands and they entire command string must be within quotes. You should see the name of the window in the upper left corner if using Viewtable to open the table.
If using EG or SAS/Studio I have no idea what may work.
Thanks. I don't believe I'm running SAS in "Display Manager".
Here's the environment I'm working in...everything is local to my PC.
that looks like Base SAS DBCS
Correct about this being Base SAS. Unsure what DBCS stands for....double-byte character set?
@desertsp2 wrote:
Thanks. I don't believe I'm running SAS in "Display Manager".
Here's the environment I'm working in...everything is local to my PC.
Yes that is the Display Manager.
Wouldn't it be an option to use SAS Universal Viewer instead of ViewTables? This is what I use and recommend to avoid this problem (see, e.g., this thread: Close all VIEWTABLES).
Thanks - I will look into that, seems like it has some other benefits as well.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.