BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I would appreciate if someone can provide me the alternatives for the following statement which should run in SAS EG 5.1?

Log below indicates that filename statement is unsuccessful.

filename indat1 pipe  'ls -d /data/Resource/Alert/daily_files/*'  ;

ERROR: Insufficient authorization to access PIPE.

ERROR: Error in the FILENAME statement.

14 REPLIES 14
ballardw
Super User

If you can enter the ls -d /data/Resource/Alert/daily_files/* from a command line and get a successful listing then you may have an issue with the configuration of SAS. You may need to provide some details of your environment such as are you working with a server based version of SAS. If the data folder isn't subordinate to the location of the SAS current directory then it can't find it. It is a good idea to always provide a full path in a libname statement, which may need to include reference to the server the file is on.

If the command line doesn't work then it is likely an OS issue or possibly a typo for the path.

Babloo
Rhodochrosite | Level 12

I could succeed the command ls -d /data/Resource/Alert/daily_files/* from command line (UNIX server). Yes, I'm working in a server based SAS and there is no typo in my path name.

Kurt_Bremser
Super User

You are most likely operating under the -noxcmd restriction. This has to be corrected in the metadata for the workspace server.

If you can't get your admin to to it, but have the option of command line access, I suggest you run the program in batch mode. Which would prove the idiocy of keeping noxcmd to the admin.

Babloo
Rhodochrosite | Level 12

May i request you to guide me to run my command (as mentioned in my initial post) in SAS EG via batch mode?

Kurt_Bremser
Super User

You take your code as written (be aware for EG-specific things like ODS output to the EG channel) and save it to your server under "Files". In most setups this is the home directory you find yourself in when logging on via ssh (or telnet).

Then log on to the server and simply do sas programname.sas. The run will create programname.log (and programname.lst if you have output). Inspect the log file to see if it worked or what went wrong. Make changes to the code and save again, repeat until satisfactory.

jakarman
Barite | Level 11

Please explain your situation as it can be:

1/ your system-admin sas-admin doesn't like you or your are classified by them as a jerk. Is there a bypass for that?

This question is: how well do you know those guys and are you on speaking terms.

2/ Those people having done the sas-installations were just capable of typing a "setup" command. Not cooperating with your business needs. How do you solve that?

This is the service manager, project manager to coordinate but that fails when missing some input on your business needs and sas knowledge aside all internal politics.

One of the to be solved questions in this implementing a good security approach including the OS level controls. 

These are the reason why the xcmd is left closed.  Having no real OS security defined this is the last thing on not granting functions for that level.   

You could try this having it solved now you know this. (open up xcmd !)

If you have access to the relevant business security policies you could ask to how those arer related against eg ISO 27002-2013 9.4.1 as there is explicitly stated those controls are aimed at user actions to sensitive data not at using some functionality/tool.    the 9.4.4 is mentioning priviledged utilty programs, imo sas is not that (common sas users)


When you are coding something to process files in sas you can:

- use wildacards in namings. the real filename is returned

- use dopen functions the build a directory list with all information just using sas functions

  SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition

---->-- ja karman --<-----
Vladislaff
SAS Employee

You can try the following:

data dirs(keep=path name);

length name $ 200 path $ 200;

rc=filename('di','/data/Resource/Alert/daily_files/');

did=dopen('di');

memcnt=dnum(did);

do i = 1 to memcnt;

name=dread(did,i);

path=catt(pathname('di'),'/',name);

rc=filename('f',catt(pathname('di'),'/',name));

did1=dopen('f');

if did1 then output;

rc=dclose(did1);

end;

rc=dclose(did);

run;

Babloo
Rhodochrosite | Level 12

Thanks for the response.

I ran your code, but I don't see any differences  in the directory. See log below.

14         GOPTIONS ACCESSIBLE;

15         data dirs(keep=path name);

16         length name $ 200 path $ 200;

17         rc=filename('di','/data/Resource/Alert/daily_files/');

18         did=dopen('di');

19         memcnt=dnum(did);

20         do i = 1 to memcnt;

21         name=dread(did,i);

22         path=catt(pathname('di'),'/',name);

23         rc=filename('f',catt(pathname('di'),'/',name));

24         did1=dopen('f');

25         if did1 then output;

26         rc=dclose(did1);

27         end;

28         rc=dclose(did);

29         run;

NOTE: The data set WORK.DIRS has 0 observations and 2 variables.

NOTE: DATA statement used (Total process time):

      real time           0.02 seconds

      cpu time            0.01 seconds

Vladislaff
SAS Employee

Whats the output of 'ls -d /data/Resource/Alert/daily_files/*' ?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not sure if there is a Unix equivalent as don't use it at the moment.  However in DOS you can simply direct the output to a text file and then read that in:

dir c:\temp>my_dir.txt

Pop that in a batch file, run it and then run your SAS program to read that text file.

Babloo
Rhodochrosite | Level 12

Thanks.

So can we the code (tweaking to match to my folders) provided in the link to match with my initial code filename indat1 pipe  'ls -d /data/Resource/Alert/daily_files/*' ; for successful run in EG?

Ksharp
Super User

It is a macro . replace its parameter as you will .

%macro drive(dir,ext); 
  
  %let filrf=mydir; 
  
  /* Assigns the fileref of mydir to the directory and opens the directory */ 
  %let rc=%sysfunc(filename(filrf,&dir)); 
  %let did=%sysfunc(dopen(&filrf)); 
  
  /* Returns the number of members in the directory */ 
  %let memcnt=%sysfunc(dnum(&did)); 
  
  /* Loops through entire directory */ 
  %do i = 1 %to &memcnt; 
  
  /* Returns the extension from each file */ 
  %let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.); 
  
  /* Checks to see if file contains an extension */ 
  %if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&name) %then %do; 
  
  /* Checks to see if the extension matches the parameter value */ 
  /* If condition is true prints the full name to the log */ 
  %if (%superq(ext) ne and %qupcase(&name) = %qupcase(&ext)) or 
  (%superq(ext) = and %superq(name) ne) %then %do; 
  %put %qsysfunc(dread(&did,&i)); 
  %end; 
  %end; 
  %end; 
  
  /* Closes the directory */ 
  %let rc=%sysfunc(dclose(&did)); 
  
%mend drive; 

%drive( /data/Resource/Alert/daily_files/)

jakarman
Barite | Level 11

Babloo, unless you solved your xcmd setting with your admins, you can forget using pipe or any other OS commands from SAS on the Unix server (EG is more like a browser terminal). That is where you started with the error message, "ERROR: Insufficient authorization to access PIPE." 

---->-- ja karman --<-----

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 14 replies
  • 5866 views
  • 3 likes
  • 7 in conversation