Search code examples
sassas-macro

Run a macro only if the username matches the list


I am trying to run a macro based on a condition of usernames, where do I make the changes:

for ex: I have the following dataset with usernames:

data users2; 
input name$; 
    cards; 
    ABC
    DEF
    YUT
    GTR
    ; 
run;

I have a macro to call: %callmacro;

proc sql; 
select name into: usernames separated by ',' from users2; 
quit;

so I call the macro

%macro NEW(); 
%if &sysuserid in (&usernames) %then %do;
%callmacro;
%end;
%mend;


%new;

So here I get an error :

ERROR: Required operator not found in expression: ( "&sysuserid" in 
(&usernames))

I would like to run a macro only if the username matches in the list. Else is there any way I can call a WINDOWS AD group from SAS macro and check if the sysuserid exixts in that Windows AD group?


Solution

  • You could check the usernames inside the macro

    %macro ThisIsConditionallyRestricted(nametable=users2);
      proc sql noprint;
        select name from &nametable where name = "&sysuserid";
      quit;
      %if &SQLOBS = 0 %then %do;
        %put WARNING: You were not prepared!;
        %return;
      %end;
      … 
    %mend;
    
    %ThisIsConditionallyRestricted;