Published on :
Macro EXTERNE

Check Numeric Type of a Variable (Macro AHGvarisnum)

This code is also available in: Deutsch Español Français
The %AHGvarisnum macro queries the metadata of a table (dsn parameter) to determine the type of a variable (var parameter). It relies on third-party macros (%AHGgettempname, %AHGvarinfo, %AHGequaltext) to extract this information. The result (1 for numeric, 0 otherwise) is returned in a macro variable specified by the 'into' parameter.
Data Analysis

Type : EXTERNE


The macro operates on an existing table provided as a parameter (dsn) during the call.

1 Code Block
DATA STEP
Explanation :
Defines the macro that initializes a temporary table for metadata, filters on the requested variable, and uses a _NULL_ Data Step with CALL SYMPUT to export a boolean indicating if the type is numeric ('N').
Copied!
1%macro AHGvarisnum(dsn,var,into=varIsNum);
2%local varinfo;
3%AHGgettempname(varinfo);
4%AHGvarinfo(&dsn,out=&varinfo,info= name type);
5DATA _null_;
6 SET &varinfo(where=(%AHGequaltext(name,"&var") ) );
7 IF type='N' THEN call symput("&into",'1');
8 ELSE call symput("&into",'0');
9RUN;
10%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.