<?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: two questions on an sas example in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/two-questions-on-an-sas-example/m-p/923210#M363489</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, you could do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let dsid = %sysfunc(open(&amp;amp;ds)) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks like the macro was designed to create a global macro variable named DSET which is the the name of the dataset, and global macro variables NVARS and NOBS.&amp;nbsp; &amp;nbsp;The macro variable DS will be a local macro variable since it is a parameter to the macro.&amp;nbsp; So if they wanted to create a global macro variable, this explains they need the %GLOBAL statement and the %LET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for needing to OPEN a dataset to get this variable information, this is only necessary if you want to use&amp;nbsp;&lt;SPAN&gt;SAS File I/O functions.&amp;nbsp; There are other ways you could get this information, for example with PROC CONTENTS.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Apr 2024 16:38:10 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2024-04-05T16:38:10Z</dc:date>
    <item>
      <title>two questions on an sas example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/two-questions-on-an-sas-example/m-p/923205#M363486</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am reading a sample code from help file and have a question:&lt;/P&gt;
&lt;P&gt;why we need&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt; %let dset=&amp;amp;ds;
   %let dsid = %sysfunc(open(&amp;amp;dset));&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;1.&amp;nbsp;can&amp;nbsp;we&amp;nbsp;do&amp;nbsp; %let dsid = %sysfunc(open(&amp;amp;ds)); instead?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;2. why we need open dataset&amp;nbsp;in&amp;nbsp;order&amp;nbsp;to&amp;nbsp;get info?&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro obsnvars(ds);
   %global dset nvars nobs;
   %let dset=&amp;amp;ds;
   %let dsid = %sysfunc(open(&amp;amp;dset));
   %if &amp;amp;dsid %then
      %do;
         %let nobs =%sysfunc(attrn(&amp;amp;dsid,NOBS));
         %let nvars=%sysfunc(attrn(&amp;amp;dsid,NVARS));
         %let rc = %sysfunc(close(&amp;amp;dsid));
         %put &amp;amp;dset has &amp;amp;nvars  variable(s) and &amp;amp;nobs observation(s).;
      %end;
   %else
      %put Open for data set &amp;amp;dset failed - %sysfunc(sysmsg());
%mend obsnvars;
%obsnvars(Sasuser.Houses)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 16:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/two-questions-on-an-sas-example/m-p/923205#M363486</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-04-05T16:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: two questions on an sas example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/two-questions-on-an-sas-example/m-p/923210#M363489</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, you could do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let dsid = %sysfunc(open(&amp;amp;ds)) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks like the macro was designed to create a global macro variable named DSET which is the the name of the dataset, and global macro variables NVARS and NOBS.&amp;nbsp; &amp;nbsp;The macro variable DS will be a local macro variable since it is a parameter to the macro.&amp;nbsp; So if they wanted to create a global macro variable, this explains they need the %GLOBAL statement and the %LET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for needing to OPEN a dataset to get this variable information, this is only necessary if you want to use&amp;nbsp;&lt;SPAN&gt;SAS File I/O functions.&amp;nbsp; There are other ways you could get this information, for example with PROC CONTENTS.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 16:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/two-questions-on-an-sas-example/m-p/923210#M363489</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-04-05T16:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: two questions on an sas example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/two-questions-on-an-sas-example/m-p/923212#M363490</link>
      <description>&lt;P&gt;1) the first is just to store value of DS in a global macrovariable DSET, because by macro arguments are local in their scope&lt;/P&gt;
&lt;P&gt;2) the dataset has to be opened to reserve it for use and to access its metadata (it's like entering a room, first you need to open the door)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 16:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/two-questions-on-an-sas-example/m-p/923212#M363490</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-04-05T16:41:01Z</dc:date>
    </item>
  </channel>
</rss>

