Putting Labels in Titles

From sasCommunity
Jump to: navigation, search

Q: How do I place data set or variable labels in titles?

A: use scl function to open data set and read attributes.

Notes:

  • expected use: in macro subroutine
  • reason: to avoid placing labels

which often have special characters, such as unmatch parenthesis, ampersand or percent signs into macro variables

  • todo: remove or handle special characters; suggest use translate

testing program:

 /* name: C:\RJF2\SAS-book\Lp-SCL\sas\RnD-labels-to-titles.sas;
description:
purpose    :
****/
%Let Data = Work.Testing;
%Let Var  = X;
 
DATA &Data.(label = 'RnD-labels-to-titles');
attrib x length = 4 label = 'variable x label';
X=1;
output;
stop;
run;
 
PROC Print data = Work.Testing;
 
%let Dsid   = %sysfunc(open  (&Data.     ));
%let Nobs   = %sysfunc(attrn (&Dsid.,Nobs));
%let Nvars  = %sysfunc(attrn (&Dsid.,Nvars));
%let VarNum = %sysfunc(varnum(&Dsid.,&Var.));
 
title3 "label, data: %sysfunc(attrc   (&Dsid.,label))";
title4 "label, var : %sysfunc(varlabel(&Dsid.,&Varnum.))";
 
*CloseExit:;   %let Rc = %sysfunc(close(&Dsid.));

listing:

The SAS System      21:53 Saturday, June 26, 2010   1
 
label, data: RnD-labels-to-titles
label, var : variable x label
 
Obs    x
 
 1     1

--macro maven == the radical programmer 01:09, 27 June 2010 (UTC)