/*------------------------------------------------------------------* | MACRO NAME : nobs | SHORT DESC : Create a macro variable for the number of | observations in a data set *------------------------------------------------------------------* | CREATED BY : Unknown, Unknown (04/08/2004 13:33) *------------------------------------------------------------------* | PURPOSE | | This macro creates a macro variable containing the number of | observations in a SAS dataset. The following parameters are used on | the macro call: | | lib= libname of the SAS library containing your dataset. | The default is WORK. | | dsn= name of the SAS dataset. No default. | | macvar= name of the global macro variable containing the number | of observations. Default is nobs. | If you specify a non-existent libname or dataset name the macro | variable returns a blank which will probably cause an error when the | macro variable is referenced later in your program. *------------------------------------------------------------------* | OPERATING SYSTEM COMPATIBILITY | | UNIX SAS v8 : YES | UNIX SAS v9 : | MVS SAS v8 : | MVS SAS v9 : | PC SAS v8 : | PC SAS v9 : *------------------------------------------------------------------* | Copyright 2004 Mayo Clinic College of Medicine. | | This program is free software; you can redistribute it and/or | modify it under the terms of the GNU General Public License as | published by the Free Software Foundation; either version 2 of | the License, or (at your option) any later version. | | This program is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | General Public License for more details. *------------------------------------------------------------------*/ %macro nobs(lib=WORK,dsn=,macvar=nobs); %local notes; %global &macvar; proc sql; reset noprint; select setting into :notes from dictionary.options where optname='NOTES'; quit; options nonotes; %let lib=%upcase(&lib); %let dsn=%upcase(&dsn); %let error=0; %let &macvar= ; %let n= ; %if &dsn= %then %do; %put ERROR: NO DATASET SPECIFIED.; %let error=1; %end; %if &error=0 %then %do; proc sql; reset noprint; select nobs into :n from dictionary.tables where libname="&lib" & memname="&dsn"; quit; %if &n= %then %do; %put ERROR: DATASET NOT FOUND.; %end; %else %let &macvar=&n; %end; options ¬es; %mend nobs;