Files
SAS_PACKAGES/packages/gsm.md
yabwon 2ce8a83499 **GSM** (Generate Secure Macros) package, version 0.11
**GSM** (Generate Secure Macros) package, version 0.11

The Package allows to create secured macros stored in SAS Proc FCMP functions. The dataset with functions can be shared between different operating systems and allows to generate macros on site without showing their code.
2021-07-19 12:58:52 +02:00

7.6 KiB


The GSM package [ver. 0.11]

The GSM (a.k.a. Generate Secure Macros) package allows to create secured macros stored in SAS Proc FCMP functions. The dataset with functions can be shared and allows to generate macros without showing their code.

The GSM package is basically an automated version of the following:

proc fcmp outlib = work.gsm.secure ENCRYPT;
  function generateMacro() $;
    rc = RESOLVE('
      %macro secretMacro(x) / SECURE;
        data test;
         a = "&x.";
        run;
      %mend;
    ');
    return (rc);
  endsub;
run;

/* share work.gsm dataset */
options cmplib = work.gsm;
data _null_;
  rc = generateMacro();
  put rc=;
run;

/* enjoy */
%secretMacro(42)

See examples for more details.

How to use it:

  • Copy all files with your macros into a directory. Best approach is to have one file for one macro.
  • Copy a path the directory.
  • Run the following code:
    %GSM(<path to directory>, cmplib=<name of the dataset>)
    
  • Share generated ZIP file (unzip and run the code).

Limitations: Single macro file cannot be longer than 32760 bytes.


Package contains:

  1. macro gsm
  2. macro gsmpck_makefcmpcode

Required SAS Components: Base SAS Software

  • SAS package generated by generatePackage, version 20210528 *

The SHA256 hash digest for package BasePlus: 4322D79C382B9D58EF5E51AFD0856331F8B38B1B35AC21295DADFC43F81B2AF8

>>> %GSM() macro: <<<

The %GSM() macro is the main macro of the GSM (a.k.a. Generate Secure Macros) package.

It converts a list of macros provided by the user into a data set of the Proc FCMP functions. The macros are stored as encrypted code which allow to share the macros without showing their code.

As a result a zip file, containing dataset with functions and code to be executed on site, is generated.

Since encrypted code is stored in a SAS dataset it has no limitation in sharing between operating systems (like catalogs have).

Limitation: Due to the Resolve() function limitations a single macro file cannot be longer than 32760 bytes.

Notes:

  • All macros have to have the secure option added, i.e. %macro aMacroname(...) / SECURE ;.
  • During the execution a test macro, named %GSMpck_dummyMacroForTests(), is generated.
  • The %GSM() macro calls the %GSMpck_makeFCMPcode(...) macro internally.

SYNTAX:

The basic syntax is the following, the <...> means optional parameters:

%GSM( 
   path
 <,trim=0>
 <,cmplib=work.generateMacros>
 <,source2=>
 <,outpath=>
)

Arguments description:

  1. path - Required, indicates a directory which contains files with macros. Only files with sas extension are used.
  • trim= - Optional, the default value is 0. If set to 1 then lines of macro code are trimmed. If set to 2 then lines of macro code are stripped.

  • cmplib= - Optional, the default value is work.generateMacros. Names the dataset which will contain generated functions.

  • source2= - Optional, the default value is null. Indicate if %includ-ed files are printed out. Any value other than null enables printing.

  • outpath= - Optional, the default value is set the same as the path. Points a directory in which a result (a zip file) is generated.


Example:

Example 1. Prepare 2 files: f1.sas and f2.sas and use the %GSM() macro.

%let path = %sysfunc(pathname(work))/path2files;

%put &=path.;
options dlcreatedir;
libname path "&path.";
filename path "&path.";

data _null_;
  file path(f1.sas);
  input;
  put _infile_;
cards4;
%macro abc(x) / SECURE;
  data test;
    do i = 1 to &x.;
      put i=;
    end;
  run;
%mend;
;;;;
run;

data _null_;
  file path(f2.sas);
  input;
  put _infile_;
cards4;
%macro xyz(x) / SECURE;
  %do i = 1 to &x.;
    %put &i=;
  %end;
%mend;
;;;;
run;

%GSM(&path., cmplib=work.myMacros)

>>> %GSMpck_makeFCMPcode() macro: <<<

The %GSMpck_makeFCMPcode() macro is an internal macro of the GSM (a.k.a. Generate Secure Macros) package.

It executes a process of converting a macro provided by the user into a Proc FCMP function.

Since encrypted code is stored in a SAS dataset it has no limitation in sharing between operating systems (like catalogs have).

Limitation: Single macro file cannot be longer than 32760 bytes.

SYNTAX:

The basic syntax is the following, the <...> means optional parameters:

%GSMpck_makeFCMPcode( 
   path
  ,number
 <,trim=0>
 <,outlib=work.generateMacros.secure>
 <,source2=>
 <,fileNameCode=FNC>
)

Arguments description:

  1. path - Required, indicates a directory which contains files with macros. Only files with sas extension are used.

  2. number - Required, a sequential number.

  • trim= - Optional, the default value is 0. If set to 1 then lines of macro code are trimmed. If set to 2 then lines of macro code are stripped.

  • cmplib= - Optional, the default value is work.generateMacros. Names the dataset which will contain generated functions.

  • source2= - Optional, the default value is null. Indicate if %includ-ed files are printed out. Any value other than null enables printing.

  • fileNameCode= - Optional, the default value is FNC. Internal fileref.


License

Copyright (c) 2021 Bartosz Jablonski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.