Published on :
Macro CREATION_INTERNE

Macros for Canonical Naming and Versioning Management

This code is also available in: Deutsch Español Français
This source code primarily defines the `%canonicalname` macro, which allows resolving abbreviated names (e.g., `l.start`) into full names (e.g., `sas©_log_start`) based on global macro variables of type `g_handler_`. It also includes the content of the `_version` macro, which compares the SAS© system version (`&sysver`) to a required version passed as a parameter.
Data Analysis

Type : CREATION_INTERNE


The code does not manipulate data tables (datasets). It only performs operations on character strings and macro variables.

1 Code Block
MACRO
Explanation :
Definition of the `canonicalname` macro. It takes a name as input, cleans it (lowercase, space removal), and attempts to resolve a prefix (handler) if it contains a dot. If a corresponding handler exists (e.g., `g_handler_l`), it is substituted. It also handles specific logic for the `sas_lang_` prefix.
Copied!
1%macro canonicalname(name);
2 %let name=%qcmpres(%lowcase(&name.));
3 
4 %IF %LENGTH(&name.)=0 %THEN
5 %return;
6 
7 %IF "%sysfunc(count(&name., .))"="1" %THEN
8 %DO;
9 %local len;
10 %let len=%index(&name., .);
11 
12 %IF &len.=1 or &len.=%LENGTH(&name.) %THEN
13 %return;
14 %local handler;
15 %let handler=%scan(&name., 1, .);
16 %let name=%scan(&name., 2, .);
17 
18 %IF %LENGTH(&handler.)=0 %THEN
19 %let handler=%str();
20 %ELSE %IF %symexist(g_handler_&handler.) %THEN
21 %DO;
22 %let handler=&&g_handler_&handler.;
23 %END;
24 %ELSE
25 %DO;
26 %put WARNING: Handler<&handler.> not found!;
27 %return;
28 %END;
29 %let name=&handler.&name.;
30 %END;
31 %local saslang;
32 %let saslang=sas_lang_;
33 
34 %IF %index(&name., &saslang.)=1 %THEN
35 %DO;
36 %let name=%substr(&name., %eval(%LENGTH(&saslang.)+1));
37 
38 %IF %index(&name., _)>0 %THEN
39 %let name=&saslang.&name.;
40 %END;
41 %* check IF name is valid.;
42 
43 %IF %nvalid(&name.) %THEN
44 %DO;
45 &name.
46 %END;
47%mend;
2 Code Block
MACRO
Explanation :
Definition of the `_version` macro. It returns 1 (true) if the current SAS version is greater than or equal to the requested version, otherwise 0 (false).
Copied!
1%macro _version(arg1, notes=, version=&arg1);
2 
3%local RESULT;
4%let RESULT=%eval(%scan(&sysver, 1, .)*100+0%scan(&sysver, 2, .)>=%scan(&version, 1, .)*100+0%scan(&version, 2, .));
5%IF %LENGTH(¬es) %THEN %put NOTE: _VERSION is returning the value &RESULT;
6 
7&RESULT
8 
9%mend _version;
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) 2015 coco, All Rights Reserved. / Copyright (c) 2001-2006 Rodney Sparapani