Hi,
How can I fix the
ERROR: Insufficient authorization to access PIPE.
In the SASOndemand
Thanks!
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)
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.
I upload files to SAS on Demand and are in the Directory home/Myname/Test
Code
filename file1 pipe 'dir "/home/Myname/Test
The FILEEXIST function can be used instead of DIR.
Can you please give a code example with FILEEXIST function, I'm new in SAS :
Code
filename file1 pipe 'dir "/home/Myname/Test" ';
Thanks
data _null_;
rc = fileexist('/home/Myname/Test.txt');
if rc then put 'File exists';
else put 'File does not exist';
run;
Thanks!
In fact what I need is to pipe every file in directory and then make some treatment using "infile"!
This SAS Note provides a way to do what you want in the Full Code tab: https://support.sas.com/kb/45/805.html
Thanks!
I use the note but still have the same problem:
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)
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;
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.