Published on :
Macro INTERNAL_CREATION

Cross-Platform Code Retrieval Macro

This code is also available in: Deutsch Español Français
Awaiting validation
This macro, `%mx_getcode`, offers a unified approach to extract source code from various SAS© environments. It determines the execution environment (SASjs, SAS© 9, or SAS© Viya) using the `%mf_getplatform` macro. Depending on the identified platform, it delegates the retrieval task to a specific macro: `%ms_getfile` for SASjs, `%mm_getstpcode` for SAS© 9 or SAS© Metadata, and `%mv_getjobcode` for SAS© Viya. For SAS© Viya, a `DATA _NULL_` step is used to parse the provided path (`loc`) and extract the job name (`name`) and its location (`shortloc`) before calling `%mv_getjobcode`. In case of an unrecognized platform, an error message is generated.
Data Analysis

Type : INTERNAL_CREATION


The script does not process external datasets for analysis. It manipulates character strings (macro variables) to determine the execution platform and to construct parameters for code retrieval macro calls. The `DATA _NULL_` step is used for internal transformation of these strings into macro variables for Viya-specific calls.

1 Code Block
Macro
Explanation :
This block initializes the `%mx_getcode` macro with the parameters `loc` (code location) and `outref` (output file reference). It then declares the local macro variables `platform`, `name`, and `shortloc`. The `%mf_getplatform` macro is called to detect the current SAS platform, and its result is stored in the `platform` variable.
Copied!
1%macro mx_getcode(loc,outref=0
2)/*/STORE SOURCE*/;
3 
4%local platform name shortloc;
5%let platform=%mf_getplatform();
2 Code Block
Macro Call
Explanation :
If the detected platform is `SASJS`, this block is executed. It calls the `%ms_getfile` macro to retrieve the content of the SASjs file specified by the macro variable `loc` (with the `.sas` extension added) and stores it in the `outref` file reference.
Copied!
1%IF &platform=SASJS %THEN %DO;
2%ms_getfile(&loc..sas, outref=&outref)
3%END;
4 
3 Code Block
Macro Call
Explanation :
If the detected platform is `SAS9` or `SASMETA`, this block is executed. It calls the `%mm_getstpcode` macro to retrieve a Stored Process. The path to this Stored Process is provided by the `tree` parameter (the macro variable `loc`), and the retrieved code is stored in the `outref` file reference.
Copied!
1%ELSE %IF &platform=SAS9 or &platform=SASMETA %THEN %DO;
2%mm_getstpcode(tree=&loc,outref=&outref)
3%END;
4 
4 Code Block
DATA STEP & Macro Call Data
Explanation :
For the `SASVIYA` environment, this block is activated. A `DATA _NULL_` step is executed to parse the macro variable `loc`. It extracts the last component of `loc` as `name` (the job name) and the rest of the path as `shortloc`. These values are then stored in local macro variables. Finally, the `%mv_getjobcode` macro is called with these `path`, `name`, and `outref` to retrieve the Viya job code.
Copied!
1%ELSE %IF &platform=SASVIYA %THEN %DO;
2 /* extract name & path from &loc */
3 DATA _null_;
4 loc=symget('loc');
5 name=scan(loc,-1,'/');
6 shortloc=substr(loc,1,LENGTH(loc)-LENGTH(name)-1);
7 call symputx('name',name,'l');
8 call symputx('shortloc',shortloc,'l');
9 RUN;
10 %mv_getjobcode(
11 path=&shortloc,
12 name=&name,
13 outref=&outref
14 )
15%END;
5 Code Block
Message log
Explanation :
If none of the platforms (`SASJS`, `SAS9`/`SASMETA`, `SASVIYA`) are detected, this block is executed. It writes an error message to the SAS log, indicating that the platform identified by `platform` is not supported. The `%mx_getcode` macro then terminates with `%mend`.
Copied!
1%ELSE %put &sysmacroname: &platform is unsupported!!!;
2%mend mx_getcode;
3 
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 2010-2023 HMS Analytical Software GmbH, http://www.analytical-software.de. This file is part of SASUnit, the unit test framework for SAS(R) programs.