DATA Step, Macro, Functions and more

Passing Variable to macro

Reply
SAS Employee
Posts: 10

Passing Variable to macro

not the best at macros - having a basic question - here is my code

%macro groupperms(basedir);

    filename dirperm pipe "nfs4_getfacl &basedir";

run;

%mend;

data work.temp;

  set work.tempdir;

  %groupperms(path);

run;

the table work.tempdir has a character variable called path

path has a value of: /u02/projects

just not able to get the right value passed to the filename statement

Super User
Posts: 11,343

Re: Passing Variable to macro

What exactly are you trying to accomplish? FILENAME has a different call in a datastep as you are calling the filename FUNCTION not the statement. Also data set variables aren't going to be accessible to the macro processor unless you use CALL EXECUTE.

Are there more than one record in work.tempdir? If not and you want to create a fileref from work.tempdir try:

proc sql;

     select path into :basedir

     from work.tempdir;

quit;

filename dirperm pipe "nfs4_getfacl &basedir";

Super User
Super User
Posts: 7,042

Re: Passing Variable to macro

Your macro is not generating code that belongs inside of a data step.

You have asked the macro to generate a FILENAME statement using the string path as the value of the BASEDIR parameter.  So the result will be

filename dirperm pipe "nfs4_getfacl path";

But you are not even trying to access this filename, even if it was generated properly.

So your data step is just making a copy of the input data.


You probably want to using the FILEVAR option on the INFILE command instead.  Perhaps something like this:

data work.temp;

  set work.tempdir;

  filevar=catx(' ','nfs4_getfacl',path);

  do while (not eof);

    infile dirperm pipe filevar=filevar end=eof truncover;

    input facl $80. ;

    output;

  end;

run;


This will add the character variable FACL with the output of the program and generate one observation for every line that the program outputs for that particular path.  In reality you might want to read the output into more than one variable.

Ask a Question
Discussion stats
  • 2 replies
  • 219 views
  • 0 likes
  • 3 in conversation