<?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: What happens if not to close the 'opened' file? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638557#M189903</link>
    <description>&lt;P&gt;When you open a file, you lock it for your own use.&lt;/P&gt;
&lt;P&gt;It remains locked until you close the handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that the code you show is not correct. Do no try to aggregate open with other functions.&lt;/P&gt;
&lt;P&gt;Use:&lt;/P&gt;
&lt;P&gt;1. open&lt;/P&gt;
&lt;P&gt;2. attrn&lt;/P&gt;
&lt;P&gt;3. close&lt;/P&gt;
&lt;P&gt;in separate steps. Follow the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Apr 2020 01:42:37 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-04-09T01:42:37Z</dc:date>
    <item>
      <title>What happens if not to close the 'opened' file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638547#M189899</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is the macro to reveal the number of observations in a dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nobs=%sysfunc(attrn(%sysfunc(open(comp_more_one_1)),nlobs));
%put nobs= &amp;amp;nobs ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why should the opened dataset be closed further:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid=%sysfunc(close(%sysfunc(open(comp_more_one_1))));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 00:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638547#M189899</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2020-04-09T00:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: What happens if not to close the 'opened' file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638551#M189900</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have faced weird errors if a file was not closed, especially if it is further utilized in the process, therefore it is advisable to close the file explicitly using the close command. Per SAS documentation&lt;/SPAN&gt;&lt;SPAN&gt;y default, a file is opened with a control level of RECORD.&amp;nbsp;&amp;nbsp;OPEN defaults to the strongest access mode available in the engine. That is, if the engine supports random access, OPEN defaults to random access. Otherwise, files are opened with sequential access, and a system-level warning is set. If you do not close the file, it remains in the memory and may cause issues if it is utilized again in the same macro, but&amp;nbsp;&amp;nbsp;If you open a file within a DATA step, it closes automatically when the DATA step ends.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 00:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638551#M189900</guid>
      <dc:creator>vkumbhakarna</dc:creator>
      <dc:date>2020-04-09T00:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: What happens if not to close the 'opened' file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638557#M189903</link>
      <description>&lt;P&gt;When you open a file, you lock it for your own use.&lt;/P&gt;
&lt;P&gt;It remains locked until you close the handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that the code you show is not correct. Do no try to aggregate open with other functions.&lt;/P&gt;
&lt;P&gt;Use:&lt;/P&gt;
&lt;P&gt;1. open&lt;/P&gt;
&lt;P&gt;2. attrn&lt;/P&gt;
&lt;P&gt;3. close&lt;/P&gt;
&lt;P&gt;in separate steps. Follow the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 01:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638557#M189903</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-09T01:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: What happens if not to close the 'opened' file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638559#M189904</link>
      <description>&lt;P&gt;Try this for yourself:&lt;/P&gt;
&lt;PRE&gt;32         %let nobs=%sysfunc(attrn(%sysfunc(open(work.class)),nlobs));
33         %put nobs= &amp;amp;nobs ;
nobs= 19
34         
35         data class;
36           set class;
37           if age &amp;lt; 12;
38         run;

ERROR: You cannot open WORK.CLASS.DATA for output access with member-level control because WORK.CLASS.DATA is in use by you in 
resource environment DATASTEP (2).
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;says, the OPEN function creates an OS lock on the file the dataset is stored in. You will be unable to write to this SAS dataset until you release the lock.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 02:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638559#M189904</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-04-09T02:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: What happens if not to close the 'opened' file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638568#M189909</link>
      <description>&lt;P&gt;On top of what the others said, you accumulate file handles, leading to a "memory leak", or an overflow of system limits (number of concurrently open files).&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 04:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/638568#M189909</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-09T04:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: What happens if not to close the 'opened' file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/639465#M190258</link>
      <description>Thank you!</description>
      <pubDate>Mon, 13 Apr 2020 13:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happens-if-not-to-close-the-opened-file/m-p/639465#M190258</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2020-04-13T13:48:41Z</dc:date>
    </item>
  </channel>
</rss>

