Published on :
Macro CREATION_INTERNE

Dataset Option Extraction Macro

This code is also available in: Français Deutsch Español
The `_option` macro analyzes a character string passed as an argument, assumed to represent a SAS© dataset name that may include options in parentheses (e.g., `my_lib.my_table(keep=var1)`). Its purpose is to extract and return only the substring containing these options, without including the dataset name. If no parentheses are detected in the string, the macro will return no value, acting specifically as a targeted extractor.
Data Analysis

Type : CREATION_INTERNE


The macro does not interact with SAS tables nor does it read data from external sources or SASHELP. It operates exclusively on a character string provided as an argument, performing internal text manipulations to produce a substring. The 'data' processed is therefore the textual argument of the macro itself.

1 Code Block
Logging Directives
Explanation :
This block contains `%put` directives used to display informative messages in the SAS log. The first line confirms the call to the `_OPTION` macro with an execution date. The second line displays the author's copyright information. The third line (`%put;`) inserts a blank line into the log to improve readability.
Copied!
1%put NOTE: You have called the macro _OPTION, 2004-03-29.;
2%put NOTE: Copyright (c) 2001-2004 Rodney Sparapani;
3%put;
4 
2 Code Block
MACRO `_option`
Explanation :
This block defines the `_option` macro which accepts an argument `arg1` (the character string to analyze). A local macro variable `i` is declared to store the position of the first opening parenthesis `(`. The `%index` function is used to find this position. If a parenthesis is found (`%if &i %then`), the `%substr` function extracts the substring starting just after this opening parenthesis until the end of the string. This substring, supposed to contain the dataset options, is returned by the macro.
Copied!
1%macro _option(arg1);
2 
3%local i;
4 
5%let i=%index(&arg1, %str(%());
6 
7%IF &i %THEN %substr(&arg1, &i+1, %LENGTH(%substr(&arg1, &i+1)));
8 
9%mend _option;
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 : Copyright (c) 2001-2004 Rodney Sparapani. Distributed under the terms of the GNU General Public License, version 2 or later, without any explicit or implicit warranty.