This macro extracts metadata (names and labels) from a table specified by the 'dsn' parameter. It relies on the external macro '%AHGvarinfo' for extraction. A DATA Step then formats this information into a character string combining the name and label in the form 'VariableName /* Label */', useful for generating self-documented code or reports. The result is stored in an output table and can be displayed via '%AHGprt'.
Data Analysis
Type : EXTERNE
The macro expects a SAS table as input via the '&dsn' parameter. The data manipulated are the metadata (column dictionary) of this table.
1 Code Block
DATA STEP Data
Explanation : Definition of the 'AHGvarlabel' macro. It initializes the output table name if not provided, calls '%AHGvarinfo' to retrieve variable attributes, then executes a DATA Step to format a descriptive string (Name + Label as comment). It concludes with a conditional call to '%AHGprt' for display.
Copied!
%macro AHGvarlabel(dsn,out=,trim=1,print=1);
%if %AHGblank(&out) %then %let out=%AHGbasename(&dsn)_label867;
%AHGvarinfo(&dsn,out=&out,info= name label);
data &out;
format name $50. label $260.;
set &out;
keep label ;
label=trim(name)||' /*'||trim(label)||' */';
run;
%if &print %then %AHGprt;
%mend;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.