Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mf_getvarcount.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Returns number of variables in a dataset
4  @details Useful to identify those renagade datasets that have no columns!
5 
6  %put Number of Variables=%mf_getvarcount(sashelp.class);
7 
8  returns:
9  > Number of Variables=4
10 
11  @param libds Two part dataset (or view) reference.
12 
13  @version 9.2
14  @author Allan Bowe
15 
16 **/
17 
18 %macro mf_getvarcount(libds
19 )/*/STORE SOURCE*/;
20  %local dsid nvars rc ;
21  %let dsid=%sysfunc(open(&libds));
22  %let nvars=.;
23  %if &dsid %then %do;
24  %let nvars=%sysfunc(attrn(&dsid,NVARS));
25  %let rc=%sysfunc(close(&dsid));
26  %end;
27  %else %do;
28  %put unable to open &libds (rc=&dsid);
29  %let rc=%sysfunc(close(&dsid));
30  %end;
31  &nvars
32 %mend;