Published on :
Utility CREATION_INTERNE

SAS Macro _DATA: Extracting Table Name

This code is also available in: Français Deutsch Español
The `_DATA` macro takes a single argument, `arg1`, which represents a SAS© table reference (e.g., 'library.table' or 'simple_table'). It parses this string to determine if it contains a period ('.') indicating the presence of a library prefix. If a period is detected, it uses the `%scan` function to extract the second part of the string (the table name) after the period. If no period is found, it considers the entire string as the table name. In both cases, the `%lowcase` function is applied to convert the resulting table name to lowercase. Any table options (e.g., `(obs=1)`) are implicitly ignored by this extraction logic.
Data Analysis

Type : CREATION_INTERNE


The `_DATA` macro is a utility function that manipulates character strings passed as arguments. It does not directly read from or write to existing SAS tables. Its inputs are strings representing SAS table references, and its output is a character string corresponding to the extracted table name.

1 Code Block
Macro definition `_DATA`
Explanation :
This block defines the `_DATA` macro. It uses a conditional `%if` statement with `%index` to check for the presence of a period ('.') in the argument `&arg1`. If a period is present, the `%scan` macro function extracts the second element of the string (the table name), using the period and the opening parenthesis character `%str(()` as delimiters to handle table options. Otherwise, `%scan` extracts the first element using only the opening parenthesis character as a delimiter. The `%lowcase` function is applied to the result to ensure the table name is returned in lowercase. The `%str(%)` character is used to escape the opening parenthesis within `%scan`.
Copied!
1%macro _data(arg1);
2 
3%IF %index(&arg1, .) %THEN %lowcase(%scan(&arg1, 2, .%str(%())));
4%ELSE %lowcase(%scan(&arg1, 1, %str(%())));
5 
6%mend _data;
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-2007 Rodney Sparapani. This code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.