Hello,
We are trying to encrypt SAS codes, can someone guide on how can we password protect / encrypt the SAS codes?
Thanks in advance!
Since SAS programs are text files, you cannot protect by password directly.
The alternatives that come to mind quickly are
1. create a password protected zip file
You can use 7za or similar to do this on the command line, so I think it is possible to have it done from sas.
2. make sas program dataset
The sas dataset can be password protected and encrypted, so you can use that.
This can be done in the following way.
/* sas program to encrypted sas dataset */
filename enc 'c:\temp\encrypt_test.sas';
data enc(read=abc write=def alter=ghi encrypt=yes);
infile enc;
length prg $200;
input;
prg=_infile_;
run;
/* sas dataset to sas program */
filename dec 'c:\temp\decrypt_test.sas';
data _null_;
set enc(read=abc);
file dec;
BLANK = verify(prg," ")-1;
put +BLANK prg;
run;
Why do you want to do this? SAS programs have to be unencrypted to be executed.
You can save it as a macro and include the STORE and SECURE option.
Are you trying to prevent people from running the code without your permission, taking credit for your code, or editing the code?
Hey @devi001! While you cannot password-protect your raw code file since it is just text, you can store and compile DATA Step programs with the Source option to save the source code with it. If you use the source=encrypt and pw options, you can save and encrypt the source code, then retrieve it later. For more information, see: Creating A Stored Compiled DATA Step Program. The next best option would be to save all of your programs into an encrypted ZIP file.
For example, this will create a DATA Step program and save it to sasuser as foo_compiled.sas7bpgm:
data foo / pgm=sasuser.foo_compiled(source=encrypt pw=mypw);
bar = 'Hello, World!';
run;
If you attempt to view the program source without a password, you will get an error:
data pgm=sasuser.foo_compiled;
describe;
run;
ERROR: Invalid or missing ALTER password on member SASUSER.FOO_COMPILED.PROGRAM. ERROR: Unable to load DATA STEP program SASUSER.FOO_COMPILED.
Supplying the password will reveal the source code in the log:
data pgm=sasuser.foo_compiled(pw=mypw);
describe;
run;
NOTE: DATA step stored program SASUSER.FOO_COMPILED is defined as: data foo / pgm=sasuser.foo_compiled(source=encrypt pw=XXXX); bar = 'Hello, World!'; run;
To call a stored compiled program and run it, simply omit the describe statement.
data pgm=sasuser.foo_compiled(pw=mypw);
run;
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.