Published on :
Macro EXTERNE

Macro to count numeric variables in a dataset

This code is also available in: Deutsch Español Français
This macro, `%nvarsn`, acts like a function. It takes a dataset name as a parameter and returns the total number of numeric variables it contains. It relies on two sub-macros, `%varlistn` to extract the list of numeric variables and `%words` to count the number of elements in this list.
Data Analysis

Type : EXTERNE


The dataset on which the macro operates is provided as an argument ('ds') when it is called. No data is created or managed directly by the macro itself.

1 Code Block
MACRO %nvarsn
Explanation :
This block defines the `%nvarsn` macro. It accepts a `ds` argument (the dataset name). It first calls the `%varlistn(&ds)` macro to get a list of the specified dataset's numeric variable names. The result of `%varlistn` is then passed to the `%words()` macro, which counts the number of elements (words) in this list, thus returning the total number of numeric variables. The `%put` line is a diagnostic message indicating that the macro has been called.
Copied!
1%put MACRO CALLED: nvarsn v1.0;
2 
3%macro nvarsn(ds);
4 %words(%varlistn(&ds))
5%mend nvarsn;
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.
Copyright Info : This software is in the public domain. No warranty of fitness or accuracy is given or implied. The user uses this code entirely at their own risk.