Procedure features: IN= argument
This example shows a simple case of encoding a password and writing the encoded password to the SAS log.
Encode the password.
proc pwencode in='my password'; run;
6 proc pwencode in='my password'; 7 run; {sas001}bXkgcGFzc3dvcmQ= NOTE: PROCEDURE PWENCODE used (Total process time): real time 0.31 seconds cpu time 0.08 seconds
Procedure features:
IN= argument
OUT= option
This example
encodes a password and saves it to an external file
reads the encoded password with a DATA step, stores it in a macro variable, and uses it in a SAS/ACCESS LIBNAME statement.
Declare a fileref.
filename pwfile ' external-filename '
Encode the password and write it to the external file. The OUT= option specifies which external fileref the encoded password will be written to.
proc pwencode in='mypass1' out=pwfile; run;
Declare a fileref for the encoded-password file.
filename pwfile ' external-filename ';
Set the SYMBOLGEN SAS system option. The purpose of this step is to show that the actual password cannot be revealed, even when the macro variable that contains the encoded password is resolved in the SAS log. This step is not required in order for the program to work properly. For more information about the SYMBOLGEN SAS system option, see SAS Macro Language: Reference .
options symbolgen;
Read the file and store the encoded password in a macro variable. The DATA step stores the encoded password in the macro variable DBPASS. For details about the INFILE and INPUT statements, the $VARYING. informat, and the CALL SYMPUT routine, see SAS Language Reference: Dictionary .
data _null_; infile pwfile obs=1 length=l; input @; input @1 line $varying1024. l; call symput('dbpass',substr(line,1,l)); run;
Use the encoded password to access a DBMS. You must use double quotation marks ( ) so that the macro variable resolves properly.
libname x odbc dsn=SQLServer user=testuser password="&dbpass";
28 data _null_; 29 infile pwfile obs=1 length=l; 30 input @; 31 input @1 line $varying1024. l; 32 call symput('dbpass',substr(line,1,l)); 33 run; NOTE: The infile PWFILE is: File Name= external-filename , RECFM=V,LRECL=256 NOTE: 1 record was read from the infile PWFILE. The minimum record length was 20. The maximum record length was 20. NOTE: DATA statement used (Total process time): real time 3.94 seconds cpu time 0.03 seconds 34 libname x odbc SYMBOLGEN: Macro variable DBPASS resolves to {sas001}bXlwYXNzMQ== 34 ! dsn=SQLServer user=testuser password="&dbpass"; NOTE: Libref X was successfully assigned as follows: Engine: ODBC Physical Name: SQLServer
Procedure features:
IN= argument
OUT= option
Other features:
FILENAME statement with CLIPBRD access method
This example saves an encoded password to the paste buffer. You can then paste the encoded password into another SAS program or into the password field of an authentication dialog box.
Declare a fileref with the CLIPBRD access method. For more information about the FILENAME statement with the CLIPBRD accedd method, see SAS Language Reference: Dictionary .
filename clip clipbrd;
Encode the password and save it to the paste buffer. The OUT= option saves the encoded password to the fileref that was declared in the previous statement.
proc pwencode in='my password' out=clip; run;