Published on :
Macro EXTERNE

Macro AHGvarlabel - Variable Label Formatting

This code is also available in: Deutsch Español Français
Awaiting validation
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!
1%macro AHGvarlabel(dsn,out=,trim=1,PRINT=1);
2%IF %AHGblank(&out) %THEN %let out=%AHGbasename(&dsn)_label867;
3%AHGvarinfo(&dsn,out=&out,info= name label);
4DATA &out;
5 FORMAT name $50. label $260.;
6 SET &out;
7 keep label ;
8 label=trim(name)||' /*'||trim(label)||' */';
9RUN;
10 
11%IF &PRINT %THEN %AHGprt;
12%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.