BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ssafmed
Obsidian | Level 7

Hi,

 

How can I fix the

 ERROR: Insufficient authorization to access PIPE.

In the SASOndemand

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Use the version in the Full Code tab like I mentioned:

%macro drive(dir,ext);                                                                                                                  
  %local filrf rc did memcnt name i;                                                                                                    
                                                                                                                                        
  /* Assigns a fileref to the directory and opens the directory */                                                           
  %let rc=%sysfunc(filename(filrf,&dir));                                                                                               
  %let did=%sysfunc(dopen(&filrf));                                                                                                     
                                                                                                                                        
  /* Make sure directory can be open */                                                                                                 
  %if &did eq 0 %then %do;                                                                                                              
   %put Directory &dir cannot be open or does not exist;                                                                                
   %return;                                                                                                                             
  %end;                                                                                                                                 
                                                                                                                                        
   /* Loops through entire directory */                                                                                                 
   %do i = 1 %to %sysfunc(dnum(&did));                                                                                                  
                                                                                                                                        
     /* Retrieve name of each file */                                                                                                   
     %let name=%qsysfunc(dread(&did,&i));                                                                                               
                                                                                                                                        
     /* Checks to see if the extension matches the parameter value */                                                                   
     /* If condition is true print the full name to the log        */                                                                   
      %if %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then %do;                                                                       
        %put &dir\&name;                                                                                                                
      %end;                                                                                                                             
     /* If directory name call macro again */                                                                                           
      %else %if %qscan(&name,2,.) = %then %do;                                                                                          
        %drive(&dir\%unquote(&name),&ext)                                                                                               
      %end;                                                                                                                             
                                                                                                                                        
   %end;                                                                                                                                
                                                                                                                                        
  /* Closes the directory and clear the fileref */                                                                                      
  %let rc=%sysfunc(dclose(&did));                                                                                                       
  %let rc=%sysfunc(filename(filrf));                                                                                                    
                                                                                                                                        
%mend drive;                                                                                                                            
                                                                                                                                        
/* First parameter is the directory of where your files are stored. */                                                                  
/* Second parameter is the extension you are looking for.           */                                                                  
%drive(c:\temp,sas)      

 

View solution in original post

12 REPLIES 12
ballardw
Super User

Best practice on this forum is any time you get an error that you supply the entire text from the log of the code submitted as well as the error messages related.

 

SAS On Demand runs on a server and I doubt that you have any permissions to run any program other than SAS on that server. Very likely anything the would use a PIPE would relate to either a program not loaded on the server, using data that may not be on the server or both. If the the file and program exist on your local, or another machine you have access to run programs that generate pipe output, then run the program on that machine with the output piped to a text file. Then upload the text file to SODA and read the text file there.

ssafmed
Obsidian | Level 7

I upload files to SAS on Demand and are in the Directory home/Myname/Test

 

Code

filename file1 pipe 'dir "/home/Myname/Test

SASKiwi
PROC Star

The FILEEXIST function can be used instead of DIR.

ssafmed
Obsidian | Level 7

Can you please give a code example with FILEEXIST function, I'm new in SAS :

 

Code

filename file1 pipe 'dir "/home/Myname/Test" ';

 

Thanks

SASKiwi
PROC Star
data _null_;
  rc = fileexist('/home/Myname/Test.txt');
  if rc then put 'File exists';
  else put 'File does not exist';
run;
ssafmed
Obsidian | Level 7

Thanks!

In fact what I need is to pipe every file in directory and then make some treatment using "infile"!

SASKiwi
PROC Star

This SAS Note provides a way to do what you want in the Full Code tab: https://support.sas.com/kb/45/805.html

 

ssafmed
Obsidian | Level 7

Thanks!

 

I use the note but still have the same problem:

 

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
68
69 Filename filelist pipe "dir /b /s /home/ssafini0/TestRisk";
ERROR: Insufficient authorization to access PIPE.
ERROR: Error in the FILENAME statement.
70
71 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
81
SASKiwi
PROC Star

Use the version in the Full Code tab like I mentioned:

%macro drive(dir,ext);                                                                                                                  
  %local filrf rc did memcnt name i;                                                                                                    
                                                                                                                                        
  /* Assigns a fileref to the directory and opens the directory */                                                           
  %let rc=%sysfunc(filename(filrf,&dir));                                                                                               
  %let did=%sysfunc(dopen(&filrf));                                                                                                     
                                                                                                                                        
  /* Make sure directory can be open */                                                                                                 
  %if &did eq 0 %then %do;                                                                                                              
   %put Directory &dir cannot be open or does not exist;                                                                                
   %return;                                                                                                                             
  %end;                                                                                                                                 
                                                                                                                                        
   /* Loops through entire directory */                                                                                                 
   %do i = 1 %to %sysfunc(dnum(&did));                                                                                                  
                                                                                                                                        
     /* Retrieve name of each file */                                                                                                   
     %let name=%qsysfunc(dread(&did,&i));                                                                                               
                                                                                                                                        
     /* Checks to see if the extension matches the parameter value */                                                                   
     /* If condition is true print the full name to the log        */                                                                   
      %if %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then %do;                                                                       
        %put &dir\&name;                                                                                                                
      %end;                                                                                                                             
     /* If directory name call macro again */                                                                                           
      %else %if %qscan(&name,2,.) = %then %do;                                                                                          
        %drive(&dir\%unquote(&name),&ext)                                                                                               
      %end;                                                                                                                             
                                                                                                                                        
   %end;                                                                                                                                
                                                                                                                                        
  /* Closes the directory and clear the fileref */                                                                                      
  %let rc=%sysfunc(dclose(&did));                                                                                                       
  %let rc=%sysfunc(filename(filrf));                                                                                                    
                                                                                                                                        
%mend drive;                                                                                                                            
                                                                                                                                        
/* First parameter is the directory of where your files are stored. */                                                                  
/* Second parameter is the extension you are looking for.           */                                                                  
%drive(c:\temp,sas)      

 

Patrick
Opal | Level 21

@ssafmed 

Luckily there are also SAS only options available to get a directory listing that don't require OS commands.

Below code doesn't cover traversing into sub-directories but this would also be possible to do - just more coding required.
Code below based on https://support.sas.com/kb/45/805.html (full code tab).

%let path=c:\temp;
%let ext=txt;

data work.dir_list(drop=_:);
  retain path "&path";
  length fname $60;

  _rc=filename('_flist','c:\temp');
  _did=dopen('_flist');
  if _did = 0 then 
    do;
      put "Directory &path cannot be open or does not exist";
      stop;
    end;

  do _i=1 to dnum(_did);
    fname=dread(_did,_i);
    if not missing("&ext") then
      do;
        if upcase(scan(fname,-1,'.')) ne "%upcase(&ext)" then continue;
      end;
    output;
  end;

  _rc=dclose(_did);
  _rc=filename('_flist');
run;

 

Tom
Super User Tom
Super User

You have to use DOPEN() and DREAD() functions.

There are examples of how to use them on the manual pages.

 

Or just download and use this %dirtree() macro:  

filename dirtree url 'https://raw.githubusercontent.com/sasutils/macros/master/dirtree.sas';
%include dirtree;

%dirtree(/home/Myname/Test)
proc print data=dirtree;
run;
SASKiwi
PROC Star

SAS On Demand operates in a locked down mode where users are blocked from executing operating system commands. The FILENAME PIPE option requires OS command access so fails as you have found. There is no fix for this. OS command access is not allowed for security reasons.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 12 replies
  • 2758 views
  • 10 likes
  • 5 in conversation