SAS Macro to get the number of observations in a dataset...


/ Published in: SAS
Save to your folder(s)



Copy this code and paste it in your HTML
  1. options nosource;
  2. %macro RecsInDS(table,macvar);
  3. %global &macvar;
  4. %local handle rc;
  5. %let handle = %sysfunc(open(&table)); /* Open the table with open() function*/
  6. %if &handle %then
  7. %do;
  8. %let &macvar = %sysfunc(attrn(&handle, nlobs)); /* get the observation count into the macvar macro variable using the function attrn() with nlobs as the option*/
  9. %let rc = %sysfunc(close(&handle)); /* close the dataset with the close() function */
  10. %end;
  11. %PUT RecsInDS &table: &&&macvar. &macvar=&&&macvar.; /* write the Record count to the Log */
  12. %mend RecsInDS;
  13.  
  14. /*Now Call the Macro...*/
  15.  
  16. %RecsInDS(sashelp.air,obs);

URL: http://sastechies.blogspot.com/2009/11/ways-to-count-number-of-obs-in-dataset.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.