2

Is there a way to replace a data set which is currently open in the ViewTable Window?

For example, say I create the following data set:

data the_meaning_of_life;
  is = 2;
run;

I open it up and notice, oh drat!, I made a typo! I correct the code and rerun it.

data the_meaning_of_life;
  is = 42;
run;

I'm then met with the following message,

ERROR: You cannot open WORK.THE_MEANING_OF_LIFE.DATA for output access with member-level
control because WORK.THE_MEANING_OF_LIFE.DATA is in use by you in resource environment
ViewTable Window.

Of course there are workarounds. In the keys menu, I could bind

next viewtable:libref.dataset;end;

to an F key or prefix the submit button with it so that all VTs are closed before code is submitted.

I recognize that there's an assumption I'm making. I'm assuming that because the ViewTable Window is called a "ViewTable" that it is indeed a view.

According to SAS, a view is

a definition of a virtual data set that is named and stored for later use. A view contains no data; it merely describes or defines data that is stored elsewhere.

A view should be independent of the data set. It seems like the ViewTable opened when a data set is double-clicked in the SAS Explorer is not a 'true' view. So maybe my question should be revised to,

How do I view a data set as a view?

Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67

1 Answers1

1

You view a dataset as a view by creating a view and then opening it. But you have a misapprehension of what a view is; specifically, a view can lock a dataset, if it's set up to do so (in some DBMSs), while it's operating. (More on that later.)

SAS is locking the dataset, not because it has to, but because it is the right thing to do here given how it works. When dealing with the issue of "How do you handle a viewtable window when the underlying dataset is modified", you have three choices, right (maybe four)?

  • Disallow changes
  • Update the viewtable to reflect the changes
  • (maybe) Indicate to the user that it needs to be refreshed
  • Ignore the changes, let the user have out of date information

ViewTable is a concept that's quite old - and uses pretty old methods. As such, the second choice isn't really possible - it's not something running in a way that can update in real time. The third isn't really either: it again would require SAS knowing that the change happened and having the ability to update the ViewTable window, which it doesn't currently do. Right now, ViewTable just grabs the data and shows it to you, and then never checks back. And option 4 is bad because you now have the user being confused as to what "true" is, especially since ViewTable actually allows for direct editing of the data (this is never something I would do, but it is possible!).

Hence SAS goes with option 1: lock the table from any changes, so you know you have the current information.

Also, a side note; ViewTable is an AF application, it isn't actually a View. ViewTable means "view a table", not "make a view from a table".

As to how you can handle this: writing a view won't help, unfortunately. Note this:

data class;
  set sashelp.class;
run;

data class_view/view=class_view;
  set class;
run;

Run that, open the view, then rerun the first data step. Yep, you still have it locked! That's because opening the view actually tells SAS to lock the dataset(s) that the view uses, for the same reason as above.

What you can do though:

data class;
  set sashelp.class;
run;

proc print data=class;
run;

You can run that all day and it won't have any issue, since the proc print is just a static "view" that doesn't lock anything.

You can also use ODS TAGSETS.TABLEEDITOR, which gives you something a little more useful perhaps.

You can definitely use the keys options to close your tables. Better perhaps is to use Enterprise Guide, which has a nice option that tells EG to close all open datasets before running anything.

Joe
  • 62,789
  • 6
  • 49
  • 67
  • I would think a fourth choice exists, namely change the underlying data set. Of course the data set would need to be locked during access, but not beyond that. This comes, however, from thinking of a View as a snapshot on some conditions. This post https://stackoverflow.com/questions/256700/what-is-a-view-in-oracle?noredirect=1&lq=1 explains Views as a convenience layer or abstraction. Are you saying that the ViewTable I see upon double-clicking is **not** a snapshot and instead is, or is analogous, to `select * from `? – Lorem Ipsum Aug 10 '17 at 15:56
  • 1
    It is exactly analagous to that, but that's also what a view is. I did mention that fourth option (ignore the changes - that's what I mean by that, i.e. allow the changes in the underlying dataset but ignore it from a UI point of view), but that's not the choice SAS made. This is a very common issue in DB and UI design and handled in lots of different ways - all four options are taken by different products. DBs have row level locking, table level locking, cell level locking ... all sorts of possibilities. – Joe Aug 10 '17 at 16:01
  • As an aside, SAS studio *doesn't* lock tables that are open for viewing. This is convenient sometimes, but the downside is that the view doesn't reflect changes to the dataset, which can cause confusion ("why didn't my update work??") – david25272 Aug 10 '17 at 23:27