title: SAS - How to return a value from a SAS macro?
body: <p>I would like to return a value from a SAS macro I created but I'm not sure how. The macro computes the number of observations in a dataset. I want the number of observations to be returned.</p>
  
  <pre><code>%macro nobs(library_name, table_name);
    proc sql noprint;
      select nlobs into :nobs
      from dictionary.tables
      where libname = UPCASE(&amp;library_name)
        and memname = UPCASE(&amp;table_name);
    quit;
  
    *return nobs macro variable;
    &amp;nobs
  %mend;
  
  %let num_of_observations = %nobs('work', 'patients');
  </code></pre>
  
  <p>Also, I would like the <code>&amp;nobs</code> macro variable that is used within the macro to be local to that macro and not global. How can I do that?</p>