<?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: OPEN FUNCTION in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115302#M23743</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks a lot to both of you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Nov 2012 22:04:15 GMT</pubDate>
    <dc:creator>robertrao</dc:creator>
    <dc:date>2012-11-01T22:04:15Z</dc:date>
    <item>
      <title>OPEN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115299#M23740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;Could you please explain me this progeam.&lt;/P&gt;&lt;P&gt;*What is the use of %global for the 3 variables&lt;/P&gt;&lt;P&gt;*what is &lt;STRONG&gt;dsid&lt;/STRONG&gt; and &lt;STRONG&gt;rc&lt;/STRONG&gt;??Are these like any other variable we create using %Let???or do they have any special meaning????&lt;/P&gt;&lt;P&gt;Also how does this code work for several datasets???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro obsnvars(ds);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;%global dset nvars nobs;&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %let dset=&amp;amp;ds;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %let dsid = %sysfunc(open(&amp;amp;dset));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %if &amp;amp;dsid %then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let nobs =%sysfunc(attrn(&amp;amp;dsid,NOBS));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let nvars=%sysfunc(attrn(&amp;amp;dsid,NVARS));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let&lt;STRONG&gt; rc&lt;/STRONG&gt; = %sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;dset has &amp;amp;nvars&amp;nbsp; variable(s) and &amp;amp;nobs observation(s).;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %else&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put Open for data set &amp;amp;dset failed - %sysfunc(sysmsg());&lt;BR /&gt;%mend obsnvars;&lt;/P&gt;&lt;P&gt;%obsnvars(sasuser.houses)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 21:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115299#M23740</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2012-11-01T21:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: OPEN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115300#M23741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Karun,&lt;/P&gt;&lt;P&gt;%global makes the macro variables you create global. It means that you can use them outside the macro.&lt;/P&gt;&lt;P&gt;no special meanings for disd and rc. You can try to use different names. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 21:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115300#M23741</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-11-01T21:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: OPEN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115301#M23742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Now I could be completly but seems like a homework question&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%global - Refer macro documentation&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DSID contains value returned by the open&amp;nbsp; function (could stand for dataset ID, could have been called anything&lt;/P&gt;&lt;P&gt;RC as above - return code? from the close function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro can be called mulitple times by passing different Dataset names in using the DS&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Barry&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 21:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115301#M23742</guid>
      <dc:creator>twocanbazza</dc:creator>
      <dc:date>2012-11-01T21:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: OPEN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115302#M23743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks a lot to both of you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 22:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115302#M23743</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2012-11-01T22:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: OPEN FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115303#M23744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Karun,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Linlin and Barry have already answered your questions but, given your question and the others you have asked, I think one of us ought to make an important comment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code you asked about was from an example in the documentation.&amp;nbsp; Glad to see you are reading the documentation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But don't expect all of the examples in the documentation to be totally thought out, generalizable anywhere solutions.&amp;nbsp; They often are quite far from that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Linlin mentioned, some of the macro variables were made global so that they could be accessed outside of the macro.&amp;nbsp; However, they weren't all initialized in the macro and the ones with return codes (like dsid and rc) are only local.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus, if the macro is called multiple times, then fails, the global variable values will retain the values from a previous call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In short, question any examples that you don't fully understand and don't blindly take the documentation examples as Gospel.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 22:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OPEN-FUNCTION/m-p/115303#M23744</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-01T22:21:36Z</dc:date>
    </item>
  </channel>
</rss>

