BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

I am using SAS EG 7.13 on a unix server.  I was able to put the list of all the folders in a macro variable.

(see the code below).

 

%let home = %sysget(HOME);
filename _folder_ "%bquote(/)";
data filenames(keep=memname);
handle=dopen( '_folder_' );

if handle > 0 then do;
count=dnum(handle);
do i=1 to count;
memname=dread(handle,i);
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _folder_ clear;
proc sort data=filenames out=FolderList;
by memname;
run;
data FolderList;
set FolderList;
where memname not contains '.log';
run;
proc sql noprint;
select memname into :list separated by ' '
from work.FolderList;
quit;
%put &list;

 

From there, I would like to make a macro tha will search for a specific file type in each subfolder (those of the &list) and give me the name and the path of a file having the extension .sas or .log or .spds9

 

For example, 

%macro Path_Name (path=&list, FileName=.sas);

??????????????

%mend;

%Path_Name (path=&list, FileName=.sas);

 

So If I execute the above mentionned macro which is not complete, I would like to get a listing of all the file ending by .sas as well as there location.

 

We could execute the same macro to find the file ending by .log or .spd9 and so on as well as there path.

Does someone know how to get this info on a unix server.

regards

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

My bad about the missing PIPE keyword. But you have to use the UNIX command as I posted it. No extra blanks, no changing of characters, only insert your path.

filename findfile pipe "/dwh_actuariat/sasprocess/prodmens/Cer5/saspgm -name \*.sas 2>&1";

The backslash has a very special meaning in UNIX and is necessary here, and

-name

is one if the subcommands of find.

View solution in original post

12 REPLIES 12
alepage
Barite | Level 11

Hello,

 

I have very little experience with Unix.  First, how can we check if the xcmd command is enabled.

how do we use it. is it a command line that we execute from putty or is it also possible to execute it from a SAS environment and if so, how do we do that.

Regards,

 

Kurt_Bremser
Super User

First, run this:

proc options option=xcmd;
run;

If XCMD is enabled, run this:

filename findfile "find /path_to_your_programs -name \*.sas 2>&1";

data programs;
infile findfile truncover;
input program $200.;
run;
alepage
Barite | Level 11

Hello,

 

I have checked if the xcmd is enable. it is the case.

However, IF I am not wrong, you are trying to genate the unix command Find / path - name /*.sas 2>&1

but it not what we get.  Any idea how to solve that issue.

Please see the log file

 

 

Tom
Super User Tom
Super User

You need to tell SAS to use the PIPE engine to get it to treat that string as a command and not the name of a file.

filename findfile PIPE "find /dwh_actuariat/sasprocess/prodmens/Cer5/saspgm/ - name  /*.sas 2>&1";
alepage
Barite | Level 11

Hello,

 

I have added the PIPE and it works better.

However, if I want to go at a previous level, let's say from /dwh_actuariat/sasprocess/prodmens/Cer5/saspgm/

to /dwh_actuariat/sasprocess/prodmens/

 

it gives me everything, the txt file, sas file and so on.  It is like it does not interpret properly the extension.

 

Also, if I want to look at all the subfolder from /dwh_actuariat/, do I need to add more parameters with the find command.

 

Regards

 

 

Kurt_Bremser
Super User

My bad about the missing PIPE keyword. But you have to use the UNIX command as I posted it. No extra blanks, no changing of characters, only insert your path.

filename findfile pipe "/dwh_actuariat/sasprocess/prodmens/Cer5/saspgm -name \*.sas 2>&1";

The backslash has a very special meaning in UNIX and is necessary here, and

-name

is one if the subcommands of find.

alepage
Barite | Level 11

Good morning,

 

You code is very fast and works but it bring everything.  It is like it does not recognize the .sas extension.

I have made some tests with:

 

filename findfile PIPE "find /dwh_actuariat/sasprocess/prodmens/ - name \*.sas 2>&1";

filename findfile PIPE "find /dwh_actuariat/sasprocess/prodmens/ - name /*.sas 2>&1";

filename findfile PIPE "find /dwh_actuariat/sasprocess/prodmens/ - name *.sas 2>&1";

filename findfile PIPE "find /dwh_actuariat/sasprocess/prodmens/ - name .sas 2>&1";

 

and it does not make any difference. I am getting around 68000 records instead of 11000 records

 

Do you have an idea why. 

Regards

 

 

alepage
Barite | Level 11

Hello,

Thank you very much for the precision on the difference between -name and - name for Unix.

 

The following code works perfectly.  Thank you very much

 

proc options option=xcmd;
run;

filename findfile PIPE "find /dwh_actuariat/sasprocess/prodmens/ -name \*.sas 2>&1";

data programs;
infile findfile truncover;
input path $200.;
run;

SASKiwi
PROC Star

Another way is to get your server administrator to set up folder shares so you can view the folders from your PC.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 12 replies
  • 4944 views
  • 1 like
  • 5 in conversation