Published on :
Macro INTERNAL_CREATION

Sans titre

This code is also available in: Deutsch Español Français
The `AHGsetallvarnil` macro is designed to be called within a DATA STEP. It identifies all character and numeric variables available in the current data step using the implicit arrays `_character_` and `_numeric_`. For each variable, it checks if its name matches the list of exceptions provided via the `except` parameter. If the variable name is NOT in the exception list (the check being performed by the `%AHGequaltext` macro), the variable is set to missing (empty string for character, period for numeric). It is important to note a potential error in the provided code: when processing numeric variables, the condition `if not %AHGequaltext(vname(ahuigeallchar),&except)` uses `vname(ahuigeallchar)` instead of `vname(ahuigeallnum)`. This means that the exclusion of numeric variables will be based on the names of character variables, which could prevent the correct exclusion of desired numeric variables.
Data Analysis

Type : INTERNAL_CREATION


The macro operates on existing variables in the data step where it is invoked, initializing them to missing values according to their type. It does not directly call external data sources or SASHELP.

1 Code Block
MACRO DEFINITION
Explanation :
This block defines the `AHGsetallvarnil` macro with an optional `except` parameter. It declares two implicit arrays: `ahuigeallchar` for all character variables and `ahuigeallnum` for all numeric variables. Two `DO OVER` loops are used to iterate over these arrays. For character variables, if the variable name (obtained by `vname`) is not in the `except` list (checked by `%AHGequaltext`), the variable is set to an empty string `''`. For numeric variables, if the name of a character variable (potential error here, as `vname(ahuigeallchar)` is used instead of `vname(ahuigeallnum)`) is not in the `except` list, the numeric variable is set to the missing value `.`.
Copied!
1%macro AHGsetallvarnil(except=);
2 DO;
3 array ahuigeallchar _character_;
4 array ahuigeallnum _numeric_ ;
5 DO over ahuigeallchar ;
6 IF not %AHGequaltext(vname(ahuigeallchar),&except) THEN ahuigeallchar='';
7 END;
8 DO over ahuigeallnum ;
9 IF not %AHGequaltext(vname(ahuigeallchar),&except) THEN ahuigeallnum=.;
10 END;
11 DO;
12 %mend;
13 
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.