Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mf_getattrn.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Returns a numeric attribute of a dataset.
4 @details Can be used in open code, eg as follows:
5
6 %put Number of observations=%mf_getattrn(sashelp.class,NLOBS);
7 %put Number of variables = %mf_getattrn(sashelp.class,NVARS);
8
9 @param libds library.dataset
10 @param attr Common values are NLOBS and NVARS, full list in [documentation](
11 http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212040.htm)
12 @return output returns result of the attrn value supplied, or -1 and log
13 message if error.
14
15 @version 9.2
16 @author Allan Bowe
17**/
18
19%macro mf_getattrn(
20 libds
21 ,attr
22)/*/STORE SOURCE*/;
23 %local dsid rc;
24 %let dsid=%sysfunc(open(&libds,is));
25 %if &dsid = 0 %then %do;
26 %put %str(WARN)ING: Cannot open %trim(&libds), system message below;
27 %put %sysfunc(sysmsg());
28 -1
29 %end;
30 %else %do;
31 %sysfunc(attrn(&dsid,&attr))
32 %let rc=%sysfunc(close(&dsid));
33 %end;
34%mend mf_getattrn;