title: How to run part of macro based on number of observations in work file in SAS
body: <p>I'm pretty new to doing macros on SAS so apologies in advance if my questions seems basic.</p>
  <p>I'm looking to execute part of a macro if there are a minimum number of observations found in temporary work file.</p>
  <p>If there are a minimum number of observations, the macro should execute a proc export of that temporary work file, otherwise it will just produce an error message on the log.</p>
  <p>I'm not sure what I'm doing wrong, the temporary work file has more than 1 observation and I want the macro to run, however it produces the error message as if it has less than the minimum.</p>
  <p>Below is the code that I've created so far - any help you have to offer will be greatly welcomed.</p>
  <pre><code>data original_data;
  set data.dataset;
  
  keep column1 column2 column3 ;
  run;
  
  
  %macro test_macro;
  
  %let dsid=%sysfunc(open(work.original_data));
  %let nobs=%sysfunc(attrn(&amp;dsid,nobs));
  %let dsid=%sysfunc(close(&amp;dsid));
  
  
  %if &amp;nobs &gt;1 %then %do;
  %put ERROR: No observations counted;
  %return
  %end
  
  %else %do;
  
  proc export data=submissions
          outfile='C:\Users\myusername\Desktop\test.csv'
          DBMS=csv replace; 
  run;
  
  %end;
  
  %mend test_macro;
  
  %test_macro
  </code></pre>