<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Concurrent read/write to datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53170#M11252</link>
    <description>Hi again&lt;BR /&gt;
Thanks for answer.&lt;BR /&gt;
&lt;BR /&gt;
When i was writing first message i didn't have enough knowledge about how do we use shared table and how we lock it.&lt;BR /&gt;
&lt;BR /&gt;
We are trying to lock it with Lock statement exactly the way it is written in this paper&lt;BR /&gt;
&lt;A href="http://www.lexjansen.com/pharmasug/2005/posters/po33.pdf" target="_blank"&gt;http://www.lexjansen.com/pharmasug/2005/posters/po33.pdf&lt;/A&gt;&lt;BR /&gt;
But it doesn't work well. In spite of some trick with SCL open\close strategy which is given in paper.&lt;BR /&gt;
The problem is, that when one process has locked the table, and another one is trying to acquire the lock with "lock TableName". Lock statement writes ERROR message in log. And it is not appropriate for our code. Because it is made in such a way, that if there is an ERROR message in log, it thinks that the process failed.&lt;BR /&gt;
And we have a long batch tree of processes, and when one of them fails(even if it worked well, but had just dummy ERROR message in log) others don't start.</description>
    <pubDate>Tue, 21 Jul 2009 08:07:53 GMT</pubDate>
    <dc:creator>Opa4ki</dc:creator>
    <dc:date>2009-07-21T08:07:53Z</dc:date>
    <item>
      <title>Concurrent read/write to datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53168#M11250</link>
      <description>Hi.&lt;BR /&gt;
&lt;BR /&gt;
I'm running SAS BASe on Solaris. I have one small table which is used for logging. Many processes use it. They use it only once and they just get new ID from this table - increment last record and store new ID in table. That's all what they do with it.&lt;BR /&gt;
&lt;BR /&gt;
The issue is that processes frequently fail because this table is locked.&lt;BR /&gt;
What are the general ways to workout this?&lt;BR /&gt;
&lt;BR /&gt;
We also have an SPD engine, but i didn't have good knowledge about this stuff now. Some people around me say that SPD helps with this issue. But there is and issue with SPD service itself - it fails frequently too.(actually not so frequently but one fail makes big problems).

Message was edited by: Opa4ki</description>
      <pubDate>Fri, 10 Jul 2009 09:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53168#M11250</guid>
      <dc:creator>Opa4ki</dc:creator>
      <dc:date>2009-07-10T09:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Concurrent read/write to datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53169#M11251</link>
      <description>Several paths are possible.&lt;BR /&gt;
&lt;BR /&gt;
First, you should be aware that this is a system services concern.&lt;BR /&gt;
SAS datasets are stored in system files, and system files access is managed by the OS.&lt;BR /&gt;
&lt;BR /&gt;
Some systems do provide file locking management (z/OS) other don't (UNIX, Windows).&lt;BR /&gt;
&lt;BR /&gt;
SAS have it's own solution through the SAS/Share Server ( &lt;A href="http://www.sas.com/products/share/index.html" target="_blank"&gt;http://www.sas.com/products/share/index.html&lt;/A&gt; ).&lt;BR /&gt;
&lt;BR /&gt;
But, alternatively, you can implement your own file locking management through the explicit LOCK statement.&lt;BR /&gt;
&lt;BR /&gt;
Overview:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/shrref/59595/HTML/default/a000203947.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/shrref/59595/HTML/default/a000203947.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Online documentation for the LOCK statement here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/shrref/59595/HTML/default/a000384048.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/shrref/59595/HTML/default/a000384048.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
You'll probably need this too (checking for successful LOCK):&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a000543758.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a000543758.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
I have seen other implementations, such as using an external relational DB (Oracle, DB2, SQL Server) to manage the locking problem (since the implementation of lock management is native nearly in all DB). But surely it is the more complex way to do this.&lt;BR /&gt;
&lt;BR /&gt;
If you're going for own locking management implementation, be aware of the DEADLOCK situation ( &lt;A href="http://en.wikipedia.org/wiki/Deadlock" target="_blank"&gt;http://en.wikipedia.org/wiki/Deadlock&lt;/A&gt; ).&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Fri, 10 Jul 2009 09:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53169#M11251</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-10T09:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Concurrent read/write to datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53170#M11252</link>
      <description>Hi again&lt;BR /&gt;
Thanks for answer.&lt;BR /&gt;
&lt;BR /&gt;
When i was writing first message i didn't have enough knowledge about how do we use shared table and how we lock it.&lt;BR /&gt;
&lt;BR /&gt;
We are trying to lock it with Lock statement exactly the way it is written in this paper&lt;BR /&gt;
&lt;A href="http://www.lexjansen.com/pharmasug/2005/posters/po33.pdf" target="_blank"&gt;http://www.lexjansen.com/pharmasug/2005/posters/po33.pdf&lt;/A&gt;&lt;BR /&gt;
But it doesn't work well. In spite of some trick with SCL open\close strategy which is given in paper.&lt;BR /&gt;
The problem is, that when one process has locked the table, and another one is trying to acquire the lock with "lock TableName". Lock statement writes ERROR message in log. And it is not appropriate for our code. Because it is made in such a way, that if there is an ERROR message in log, it thinks that the process failed.&lt;BR /&gt;
And we have a long batch tree of processes, and when one of them fails(even if it worked well, but had just dummy ERROR message in log) others don't start.</description>
      <pubDate>Tue, 21 Jul 2009 08:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53170#M11252</guid>
      <dc:creator>Opa4ki</dc:creator>
      <dc:date>2009-07-21T08:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Concurrent read/write to datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53171#M11253</link>
      <description>Well in theory, the QUERY or SHOW options of the LOCK statement should allow you to check if a table has been locked by some other process.&lt;BR /&gt;
&lt;BR /&gt;
Actually there is a bug, and those options might not work as expected:&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/2/859.html" target="_blank"&gt;http://support.sas.com/kb/2/859.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
But, if the log is the only problem, try the following macro:&lt;BR /&gt;
&lt;BR /&gt;
%macro lock_try(DATA);&lt;BR /&gt;
filename tempfile temp;&lt;BR /&gt;
proc printto log=tempfile; run;&lt;BR /&gt;
lock &amp;amp;DATA;&lt;BR /&gt;
proc printto; run;&lt;BR /&gt;
%mend lock_try;&lt;BR /&gt;
&lt;BR /&gt;
%lock_try(LIB007.TAB00130);&lt;BR /&gt;
&lt;BR /&gt;
It will attempt to lock the provided table, and redirect the log to a temporary file.&lt;BR /&gt;
No message will be displayed in the log.&lt;BR /&gt;
&lt;BR /&gt;
To see if the lock was successful, just check the value of the SYSLCKRC automatic macro variable.&lt;BR /&gt;
&lt;BR /&gt;
More about redirecting output/log to a file:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001330273.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001330273.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Tue, 21 Jul 2009 13:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concurrent-read-write-to-datasets/m-p/53171#M11253</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-21T13:18:46Z</dc:date>
    </item>
  </channel>
</rss>

