Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the more complete example that @cmjohns was talking about. It will return 0 if it is empty, -1 if it is missing, and has options to handle deleted observations and where clauses (note that using a where clause can make the macro take a long time on very large datasets). </p> <p><strong>Usage Notes:</strong></p> <p>This macro will return the number of observations in a dataset. If the dataset does not exist then -1 will be returned. I would not recommend this for use with ODBC libnames, use it only against SAS tables.</p> <p>Parameters:</p> <ul> <li>iDs - The <code>libname.dataset</code> that you want to check.</li> <li>iWhereClause (<em>Optional</em>) - A where clause to apply</li> <li>iNobsType (<em>Optional</em>) - Either <code>NOBS</code> OR <code>NLOBSF</code>. See <a href="http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p12uchp7hm5h2zn1om2ut816af7h.htm" rel="nofollow">SASV9 documentation</a> for descriptions.</li> </ul> <p><strong>Macro definition:</strong></p> <pre><code>%macro nobs(iDs=, iWhereClause=1, iNobsType=nlobsf, iVerbose=1); %local dsid nObs rc; %if "&amp;iWhereClause" eq "1" %then %do; %let dsID = %sysfunc(open(&amp;iDs)); %end; %else %do; %let dsID = %sysfunc(open(&amp;iDs(where=(&amp;iWhereClause)))); %end; %if &amp;dsID %then %do; %let nObs = %sysfunc(attrn(&amp;dsID,nlobsf)); %let rc = %sysfunc(close(&amp;dsID)); %end; %else %do; %if &amp;iVerbose %then %do; %put WARNING: MACRO.NOBS.SAS: %sysfunc(sysmsg()); %end; %let nObs = -1; %end; &amp;nObs %mend; </code></pre> <p><strong>Example Usage:</strong></p> <pre><code>%put %nobs(iDs=sashelp.class); %put %nobs(iDs=sashelp.class, iWhereClause=height gt 60); %put %nobs(iDs=this_dataset_doesnt_exist); </code></pre> <p><strong>Results</strong></p> <pre><code>19 12 -1 </code></pre> <p><strong>Installation</strong></p> <p>I recommend setting up a <a href="http://support.sas.com/kb/24/451.html" rel="nofollow">SAS autocall library</a> and placing this macro in your autocall location. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload