<?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: MVAR use in proc Template in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4964#M1998</link>
    <description>There certainly is Cynthia.  I wrote this macro into my toolkit in 2000, so I haven't looked at any changes of behaviour in the move from V6 to SAS8 and later.&lt;BR /&gt;
&lt;BR /&gt;
%Macro XGetDNob( MDSName = ,   /* NObs in this data set */&lt;BR /&gt;
                 MMacVar =  )  /* Place NObs in this macro */&lt;BR /&gt;
       / /*Store*/  Des = 'Get data set observation count to macro';&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
  %Local  DSid;&lt;BR /&gt;
 &lt;BR /&gt;
  %Global &amp;amp;MMacVar;&lt;BR /&gt;
 &lt;BR /&gt;
  %Let &amp;amp;MMacVar = -1;  /* If data set does not exist,&lt;BR /&gt;
                          force -1 return value */&lt;BR /&gt;
 &lt;BR /&gt;
  %Let DSid = %SysFunc( Open( &amp;amp;MDSName) );&lt;BR /&gt;
 &lt;BR /&gt;
  %If &amp;amp;DSid  %Then  %Do;&lt;BR /&gt;
 &lt;BR /&gt;
    %Let &amp;amp;MMacVar  = %SysFunc( Attrn( &amp;amp;DSid, NLObs) );&lt;BR /&gt;
 &lt;BR /&gt;
    %Let SysRc  = %SysFunc( Close( &amp;amp;DSid) );&lt;BR /&gt;
    %If &amp;amp;SysRc  %Then&lt;BR /&gt;
        %Put Macro Call Error: Data Set &amp;amp;MDSName was not closed properly;&lt;BR /&gt;
 &lt;BR /&gt;
  %End;&lt;BR /&gt;
 &lt;BR /&gt;
  %Else %Put Macro Call error: - %SysFunc( SysMsg( ) );&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
%Mend XGetDNob;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
There was an extended version I also wrote that could retrieve any data set attribute.  With the extended V9 data set attributes, this has proven very useful as well.&lt;BR /&gt;
&lt;BR /&gt;
I know you recognise the meaning of the attribute NLObs, but it is worth documenting that it is the number of Logical Observations, and will not include obs marked for deletion, which are otherwise included in the NObs count.  It is a reminder that when you look under the bonnet in SAS, you need to know what you are looking for.&lt;BR /&gt;
&lt;BR /&gt;
Kind regards&lt;BR /&gt;
&lt;BR /&gt;
David</description>
    <pubDate>Sat, 06 Oct 2007 00:50:25 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2007-10-06T00:50:25Z</dc:date>
    <item>
      <title>MVAR use in proc Template</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4962#M1996</link>
      <description>Hi all.&lt;BR /&gt;
I was wondering why the following test did not work : I've tried to change the template for the SQL procedure so that a header includes both editing date and number of rows listed. For the date, I declared the system macro-variable SYSDATE9 in a MVAR statement in proc Template ; for the number of rows, I used the SQLOBS system macro-variable in the same way.&lt;BR /&gt;
SYSDATE9 works out fine ; SQLOBS does not (it resolves to zero in the header ; but a %PUT shows that it resolves to 19).&lt;BR /&gt;
I guess that it has to do with a synchronization problem between the template and the Sql procedure. But I am not really clear about that : I thought that the query result was already built up before being sent to ODS, and hence the SQLOBS should have been given a value at that time !&lt;BR /&gt;
&lt;BR /&gt;
Does someone have a clearer view on what's happening than mine ? Thanks in advance.&lt;BR /&gt;
&lt;BR /&gt;
Olivier&lt;BR /&gt;
&lt;BR /&gt;
PROC TEMPLATE ;&lt;BR /&gt;
	EDIT Base.Sql ;&lt;BR /&gt;
		DEFINE HEADER h ;&lt;BR /&gt;
			MVAR sqlobs sysdate9 ;&lt;BR /&gt;
			TEXT "This output composed of " sqlobs " observations was produced on " sysdate9 "..." ;&lt;BR /&gt;
		END ;&lt;BR /&gt;
	END ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
PROC SQL ;&lt;BR /&gt;
	SELECT *&lt;BR /&gt;
	FROM sashelp.class ;&lt;BR /&gt;
	%PUT &amp;amp;sqlobs ;&lt;BR /&gt;
QUIT ;</description>
      <pubDate>Fri, 05 Oct 2007 08:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4962#M1996</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2007-10-05T08:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: MVAR use in proc Template</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4963#M1997</link>
      <description>Olivier:&lt;BR /&gt;
  I think you may be running into this. Even though the doc is referring to data step created macro vars, this is what it says:&lt;BR /&gt;
&lt;B&gt;"You cannot use a macro variable reference to retrieve the value of a macro variable in the same program (or step) in which SYMPUT creates that macro variable and assigns it a value."&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
  Or, if you prefer to think of it a separate way...think of the header being written at  the "top" of the file. So, at the time the header needs to be written, no step boundary has yet occurred. A different way to accomplish the same thing is:&lt;BR /&gt;
[pre]&lt;BR /&gt;
PROC TEMPLATE ;&lt;BR /&gt;
  EDIT Base.Sql ;&lt;BR /&gt;
  MVAR nobs sysdate9 ;&lt;BR /&gt;
    DEFINE HEADER h ;&lt;BR /&gt;
      TEXT "This output composed of " nobs " observations was produced on " sysdate9 "..." ;&lt;BR /&gt;
    END ;&lt;BR /&gt;
  END ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
    &lt;BR /&gt;
ods listing;&lt;BR /&gt;
PROC SQL ;&lt;BR /&gt;
select nobs into :nobs&lt;BR /&gt;
   from dictionary.tables&lt;BR /&gt;
   where libname = 'SASHELP' and&lt;BR /&gt;
         memname = 'CLASS';&lt;BR /&gt;
     &lt;BR /&gt;
%put nobs is &amp;amp;nobs;&lt;BR /&gt;
%let nobs=&amp;amp;nobs;    /*  &amp;lt;------- this strips trailing blanks */&lt;BR /&gt;
     &lt;BR /&gt;
SELECT *&lt;BR /&gt;
    FROM sashelp.class ;&lt;BR /&gt;
QUIT ; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
I remember seeing a SUGI paper a while back, that showed how to get nobs using just %sysfunc and SCL functions to open the dataset, get nobs and then close the data set which might be another alternative. &lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 05 Oct 2007 14:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4963#M1997</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-10-05T14:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: MVAR use in proc Template</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4964#M1998</link>
      <description>There certainly is Cynthia.  I wrote this macro into my toolkit in 2000, so I haven't looked at any changes of behaviour in the move from V6 to SAS8 and later.&lt;BR /&gt;
&lt;BR /&gt;
%Macro XGetDNob( MDSName = ,   /* NObs in this data set */&lt;BR /&gt;
                 MMacVar =  )  /* Place NObs in this macro */&lt;BR /&gt;
       / /*Store*/  Des = 'Get data set observation count to macro';&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
  %Local  DSid;&lt;BR /&gt;
 &lt;BR /&gt;
  %Global &amp;amp;MMacVar;&lt;BR /&gt;
 &lt;BR /&gt;
  %Let &amp;amp;MMacVar = -1;  /* If data set does not exist,&lt;BR /&gt;
                          force -1 return value */&lt;BR /&gt;
 &lt;BR /&gt;
  %Let DSid = %SysFunc( Open( &amp;amp;MDSName) );&lt;BR /&gt;
 &lt;BR /&gt;
  %If &amp;amp;DSid  %Then  %Do;&lt;BR /&gt;
 &lt;BR /&gt;
    %Let &amp;amp;MMacVar  = %SysFunc( Attrn( &amp;amp;DSid, NLObs) );&lt;BR /&gt;
 &lt;BR /&gt;
    %Let SysRc  = %SysFunc( Close( &amp;amp;DSid) );&lt;BR /&gt;
    %If &amp;amp;SysRc  %Then&lt;BR /&gt;
        %Put Macro Call Error: Data Set &amp;amp;MDSName was not closed properly;&lt;BR /&gt;
 &lt;BR /&gt;
  %End;&lt;BR /&gt;
 &lt;BR /&gt;
  %Else %Put Macro Call error: - %SysFunc( SysMsg( ) );&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
%Mend XGetDNob;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
There was an extended version I also wrote that could retrieve any data set attribute.  With the extended V9 data set attributes, this has proven very useful as well.&lt;BR /&gt;
&lt;BR /&gt;
I know you recognise the meaning of the attribute NLObs, but it is worth documenting that it is the number of Logical Observations, and will not include obs marked for deletion, which are otherwise included in the NObs count.  It is a reminder that when you look under the bonnet in SAS, you need to know what you are looking for.&lt;BR /&gt;
&lt;BR /&gt;
Kind regards&lt;BR /&gt;
&lt;BR /&gt;
David</description>
      <pubDate>Sat, 06 Oct 2007 00:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4964#M1998</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-10-06T00:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: MVAR use in proc Template</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4965#M1999</link>
      <description>Thank you Cynthia and David.&lt;BR /&gt;
If I understand well, the macro-variable SQLOBS is set to zero prior to the SQL query is beign run ; that's when the Template gets its value. And then the query is run, and the correct number of rows is assigned to the SQLOBS macro-variable, but it's already too late !&lt;BR /&gt;
Well, thanks anyway for both the explanations and the circumventions.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Olivier</description>
      <pubDate>Mon, 08 Oct 2007 09:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/MVAR-use-in-proc-Template/m-p/4965#M1999</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2007-10-08T09:31:58Z</dc:date>
    </item>
  </channel>
</rss>

