Skip to content

Commit

Permalink
Merge pull request #10 from macropeople/development
Browse files Browse the repository at this point in the history
feat: new mf_getattrc macro
  • Loading branch information
allanbowe committed Mar 17, 2020
2 parents b73d876 + 4e45575 commit 6986814
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
34 changes: 34 additions & 0 deletions base/mf_getattrc.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
@file
@brief Returns a character attribute of a dataset.
@details Can be used in open code, eg as follows:
%put Dataset label = %mf_getattrc(sashelp.class,LABEL);
%put Member Type = %mf_getattrc(sashelp.class,MTYPE);
@param libds library.dataset
@param attr full list in [documentation](
https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000147794.htm)
@return output returns result of the attrc value supplied, or -1 and log
message if error.
@version 9.2
@author Allan Bowe
**/

%macro mf_getattrc(
libds
,attr
)/*/STORE SOURCE*/;
%local dsid rc;
%let dsid=%sysfunc(open(&libds,is));
%if &dsid = 0 %then %do;
%put WARNING: Cannot open %trim(&libds), system message below;
%put %sysfunc(sysmsg());
-1
%end;
%else %do;
%sysfunc(attrc(&dsid,&attr))
%let rc=%sysfunc(close(&dsid));
%end;
%mend;
33 changes: 33 additions & 0 deletions mc_all.sas
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,39 @@
0
%put Vars not found: &found;
%end;
%mend;/**
@file
@brief Returns a character attribute of a dataset.
@details Can be used in open code, eg as follows:
%put Dataset label = %mf_getattrc(sashelp.class,LABEL);
%put Member Type = %mf_getattrc(sashelp.class,MTYPE);
@param libds library.dataset
@param attr full list in [documentation](
https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000147794.htm)
@return output returns result of the attrc value supplied, or -1 and log
message if error.
@version 9.2
@author Allan Bowe
**/

%macro mf_getattrc(
libds
,attr
)/*/STORE SOURCE*/;
%local dsid rc;
%let dsid=%sysfunc(open(&libds,is));
%if &dsid = 0 %then %do;
%put WARNING: Cannot open %trim(&libds), system message below;
%put %sysfunc(sysmsg());
-1
%end;
%else %do;
%sysfunc(attrc(&dsid,&attr))
%let rc=%sysfunc(close(&dsid));
%end;
%mend;/**
@file
@brief Returns a numeric attribute of a dataset.
Expand Down

0 comments on commit 6986814

Please sign in to comment.