BookmarkSubscribeRSS Feed
RodNeal
SAS Employee

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

2 REPLIES 2
ballardw
Super User

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";

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1163 views
  • 0 likes
  • 3 in conversation