Macro for encryption --error on execution

Reply
Occasional Contributor
Posts: 9

Macro for encryption --error on execution

Can you help me to find the problem. Macro compiles but exection is throwing error in log.

 

%macro encryptsas(libpath,metalib, metafolder);
proc authlib lib="&libpath";
create securedlibrary="&metalib"
securedfolder="&metafolder"
pw=test123
require_encryption=yes
encrypt=AES
encryptkey=testkeyvalue123;
%mend encryptsas;
run;
quit;

 


%encryptsas (/var/usersdata/risk/prj/users/awais/projects/hello, Secured, Awais);

 

 

"/var/usersdata/risk/prj/users/awais/projects/hello
___________________________________________________
22
200
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.

 

 

 

 

Esteemed Advisor
Esteemed Advisor
Posts: 7,249

Re: Macro for encryption --error on execution

Lib= means a library reference to a network drive area.  You can't put the network drive in there.  So create a libname, then use that, e.g:

%macro encryptsas(libpath,metalib, metafolder);

  libname tmp "&libpath.";
  proc authlib lib=tmp;
    create securedlibrary="&metalib." 
    securedfolder="&metafolder." 
    pw=test123
    require_encryption=yes
    encrypt=AES
    encryptkey=testkeyvalue123;
  run;

%mend encryptsas;
 

%encryptsas (/var/usersdata/risk/prj/users/awais/projects/hello, Secured, Awais);

Do note I made a few corrections.

Occasional Contributor
Posts: 9

Re: Macro for encryption --error on execution

Thank you for quick response. But I would like to use libame statement outside te macro, so I can have felxiblity of  using diffrent libarary names as a parameter  while executing the macro --considring to to add the macro in autocall .

 

 

 

 

 

 

Esteemed Advisor
Posts: 6,698

Re: Macro for encryption --error on execution

Then you should supply the libname (and not the path) to the macro and use the macro variable that now holds the libname without quotes.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Esteemed Advisor
Posts: 7,249

Re: Macro for encryption --error on execution

Simple change then:

%macro encryptsas(libpath=,metalib=,metafolder=);

  proc authlib lib=&libpath.;
    create securedlibrary="&metalib." 
    securedfolder="&metafolder." 
    pw=test123
    require_encryption=yes
    encrypt=AES
    encryptkey=testkeyvalue123;
  run;

%mend encryptsas;
 
libname tmp "/var/usersdata/risk/prj/users/awais/projects/hello";
%encryptsas (libpath=tmp, metalib=secured, metafolder=wais);

You will of course then want to put in parameter validation on the three parameters - e.g. make sure library exists etc.  This would all be part of your lifecycle management documentaion and validation on the code.   

Occasional Contributor
Posts: 9

Re: Macro for encryption --error on execution

Thank you  for the updated sas code. It works but there is  problem

looks like data set does not get encrypted when 

we provide libname statemnet outside the  the Macro . Proc contenet does not show any encrption.

 

data tmp.test24;
  set sashelp.air;
  run;
proc contents data=tmp.test24;
run;

 

 Proc contents.JPG

 

Spoiler
 

I do have sas/secure  licensed and installed.  Here is the proc content and  output of another simple program

 

data salary(encrypt=aes encryptkey=green12345);
   set sashelp.air;
   run;
proc  contents data=work.salary(encryptkey=green12345);
run;

 

 

 

 

Attachment
Respected Advisor
Posts: 3,840

Re: Macro for encryption --error on execution

[ Edited ]

@Mushtaq

I believe you can't encrypt datasets in WORK.

 

Running your code sample against a permanent library works for me.

libname test 'c:\temp';

data test.salary(encrypt=aes encryptkey=green12345);
  set sashelp.air;
run;

proc  contents data=test.salary(encryptkey=green12345);
run;

Capture.JPG

 

 I personally would create a AES encrypted secured metadata bound library using SAS Management Console.

 

Once you've created such a library only SAS users having metadata access to this metadata library definition will be able to read the data - but all data created in this library will be AES encrypted without the user having to care about it.

 

 

Occasional Contributor
Posts: 9

Re: Macro for encryption --error on execution

Thank you  for the updated sas code. It works but there is  problem

looks like data set does not get encrypted when 

we provide libname statemnet outside the  the Macro . Proc contenet does not show any encrption.

 

data tmp.test24;
  set sashelp.air;
  run;
proc contents data=tmp.test24;
run;

 

 Proc contents.JPG

 

Spoiler
 

I do have sas/secure  licensed and installed.  Here is the proc content and  output of another simple program

 

data salary(encrypt=aes encryptkey=green12345);
   set sashelp.air;
   run;
proc  contents data=work.salary(encryptkey=green12345);
run;

 

 

 

 

Attachment
Attachment
Esteemed Advisor
Esteemed Advisor
Posts: 7,249

Re: Macro for encryption --error on execution

Sorry, its not making any sense, you post that this code is not doing what you expect:

data tmp.test24;

But this code is doing what you expect:

data salary(encrypt=aes encryptkey=green12345);

 

But the two are clearly very different lines of code?

 

Secondly the macro given, all this does is create the given Base SAS code:

libname tmp "/var/usersdata/risk/prj/users/awais/projects/hello";
proc authlib lib=tmp;
create securedlibrary="secured"
securedfolder="wais"
pw=test123
require_encryption=yes
encrypt=AES
encryptkey=testkeyvalue123;
run;

If the above doesn't give what you want, its probably best to speak with SAS support as I don't know enough about this proc authlib versus the datastep version you give, or anything about your setup. 

Esteemed Advisor
Posts: 6,698

Re: Macro for encryption --error on execution

Are you sure all your codes run in the same context?

When doing this:

libname seclib '$HOME/seclib';

proc authlib;
create
  library=seclib
  securedlibrary = "seclib"
  encrypt = aes
  encryptkey=XYZ
  require_encryption=yes
  pw=mypass
;
run;

data seclib.class;
set sashelp.class;
run;

proc contents data=seclib.class;
run;

seclib.class was automatically encrypted.

Note that $HOME/seclib was newly created and therefore empty.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 9

Re: Macro for encryption --error on execution

Thank you all who replied and I updated the macro and it works. But inspite I have secured library folder crated using SMC, and there are no errors/warnings  during compliation and execution of the macro,  the data set creted is not enrypted --as reported by proc contents.  Here is the code  again.

 

%macro encryptsas(libpath=,metalib=,metafolder=);

  proc authlib lib=&libpath.;
    create securedlibrary="&metalib." 
    securedfolder="&metafolder." 
    pw=test123
    require_encryption=yes
    encrypt=AES
    encryptkey=testkeyvalue123;
  run;

%mend encryptsas;
 
libname tmp "/var/usersdata/risk/prj/users/awais/projects/hello";
%encryptsas (libpath=tmp, metalib=secured, metafolder=awais);

data tmp.test25;
 set sashelp.air;
 run;
proc contents data=tmp.test25;
run;

proc contents

Ask a Question
Discussion stats
  • 10 replies
  • 129 views
  • 3 likes
  • 4 in conversation