We are using SAS 9.2.
An extract of the actual code is appended below, but please note that for security purposes I have had to edit out certain values, but I believe you should be able to follow the code.
%macro get_uid_var();
%global uid_var;
/* %let uid_var=SYSUSERID; Default value - replaced by user_id from _METADATA*/
%let uid_var=_METAUSER;
filename uvputlog '~/uvput.log';
proc printto log=uvput new;
run;
%put _all_;
proc printto;
run;
data _null_;
infile uvputlog;
input;
length inline $255;
inline=compress(_infile_,"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789:,.-()*&^%$£!","k");
if index(inline,"_EGUSERID") gt 0 then
call symput('uid_var',"_EGUSERID");
if index(inline,"_METAUSER") gt 0 then
call symput('uid_var',"_METAUSER");
run;
data _null_;
msg=sysmsg();
put rc=;
put msg=;
run;
filename uvputlog clear;
%mend;
%macro get_users_grps;
/* metadata server that contains the user information. */
options metaserver=
metaport=8561
metauser=&&&uid_var
metapass=&&pw
metaprotocol=bridge
metarepository=Foundation;
data WORK.users_grps;
length uri name userid group groupuri loginuri $256 id $30;
/* Initialize variables to missing. */
n=1;
uri='';
name='';
userid='';
group='';
groupuri='';
id='';
loginuri='';
/* Determine how many person objects are defined. */
nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
if nobj=0 then put 'No Persons available.';
else do while (nobj > 0);
/* Retrieve the current person's name & User ID. */
rc=metadata_getattr(uri, "Name", Name);
logassn=metadata_getnasn(uri,"Logins",1,loginuri);
if logassn > 0 then do;
rc3=metadata_getattr(loginuri, "UserID", UserID);
/* Get the group association information for the current person. */
a=1;
grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
/* If this person does not belong to any groups, set their group */
/* variable to 'No groups' and output the name. */
if grpassn in (-3,-4) then do;
group="No groups";
output;
end;
/* If the person belongs to any groups, loop through the list */
/* and retrieve the name of each group, outputting each on a */
/* separate record. */
else do while (grpassn > 0);
rc2=metadata_getattr(groupuri, "Name", group);
a+1;
output;
grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
end;
end;
/* Retrieve the next person's information. */
n+1;
nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
end;
keep name userid group;
run;
%mend;
%macro display_exceptions(Region=,Area=,DateFrom=,DateTo=);
/* identify the Users UID */
%get_uid_var;
/* Identify the groups that the user belongs to, using uid as parameter */
%get_users_grps;
/* Initialise the display exceptions marker prior to confirming whether or not the user has access permissions) */
%let display_exception="N";
/* If Metadata server query fails, do not display exceptions */
proc sql noprint;
select count(*) into :num_recs from users_grps
where group in ('Testers');
quit;
%if &num_recs eq 0 %then %do; /* This is 0 as @corp not the same as */
%let display_exceptions="N";
title "***** ACCESS WARNING – Access Denied ******";
data WORK.TEMP;
length Warning $180;
Warning="You are not authorised to have access to this area.";
output;
Warning="If you believe you should have access then please contact the";
output;
Warning="System Administrator.";
output;
run;
proc print data=WORK.TEMP noobs;
run;
%end;
………