BookmarkSubscribeRSS Feed
Mushtaq
Calcite | Level 5

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.

 

 

 

 

10 REPLIES 10
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Mushtaq
Calcite | Level 5

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 .

 

 

 

 

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.   

Mushtaq
Calcite | Level 5

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;

 

 

 

 


Salary dataset contents.JPG
Patrick
Opal | Level 21

@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.

 

 

Mushtaq
Calcite | Level 5

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;

 

 

 

 


Salary dataset contents.JPGSalary dataset contents.JPG
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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. 

Kurt_Bremser
Super User

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.

Mushtaq
Calcite | Level 5

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1553 views
  • 3 likes
  • 4 in conversation