SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

how to get list of files available in Directory including sub folder in SAS

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

how to get list of files available in Directory including sub folder in SAS

Hi , i was trying to get  list of files(.csv) available in Directory including sub folder in SAS,please help me.

 

code

%macro list_files(dir,ext);
%local filrf rc did memcnt name i;
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));

%if &did eq 0 %then %do;
%put Directory &dir cannot be open or does not exist;
%return;
%end;

%do i = 1 %to %sysfunc(dnum(&did));

%let name=%qsysfunc(dread(&did,&i));

/* %if %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then %do;*/
%if %qscan(&name,2,.) ne %then %do;
%put &dir\&name;

data _tmp;
length dir $512 name $100;
dir=symget("dir");
name=symget("name");
run;
proc append base=want data=_tmp;
run;quit;

%end;
%else %if %qscan(&name,2,.) = %then %do;
%list_files(&dir\&name,&ext)
%end;

%end;
%let rc=%sysfunc(dclose(&did));
%let rc=%sysfunc(filename(filrf));

%mend list_files;
%list_files("C:\Users\sivakumar.sivaraj\Documents\Dataset",*)

 

 

Error - ''The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space 
between a quoted string and the succeeding identifier is recommended''


1 ;*'
_
49
1 ! ;*";*/;quit;run;
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.

2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program'
_______________________________
49
3 ! ;

NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.

4 %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5 %LET _CLIENTPROJECTPATH='';
6 %LET _CLIENTPROJECTNAME='';
7 %LET _SASPROGRAMFILE=;
8
9 ODS _ALL_ CLOSE;
10 OPTIONS DEV=ACTIVEX;
11 GOPTIONS XPIXELS=0 YPIXELS=0;
12 FILENAME EGSR TEMP;
13 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
14 STYLE=HtmlBlue
15 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
NOTE: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation
marks.

 


Accepted Solutions
Solution
‎01-24-2018 07:21 AM
Super User
Super User
Posts: 9,416

Re: how to get list of files available in Directory including sub folder in SAS

Posted in reply to sivastat08

Sorry, I can't read that.  What software are you using, is it Windows/Unix/Server based?  Simplest method is to use the operating system if you have access, so for windows:

filename tmp pipe 'dir "c:/somewhere/*.csv" /b /s';

data want;
  infile tmp dlm="¬";
  length cmd_line $2000;
  input cmd_line;
run;

Want then contains the basics directory listing (/b) with all subdirectories (/s) only csv files.  Without more on the rest of the process its hard to say.

View solution in original post


All Replies
Solution
‎01-24-2018 07:21 AM
Super User
Super User
Posts: 9,416

Re: how to get list of files available in Directory including sub folder in SAS

Posted in reply to sivastat08

Sorry, I can't read that.  What software are you using, is it Windows/Unix/Server based?  Simplest method is to use the operating system if you have access, so for windows:

filename tmp pipe 'dir "c:/somewhere/*.csv" /b /s';

data want;
  infile tmp dlm="¬";
  length cmd_line $2000;
  input cmd_line;
run;

Want then contains the basics directory listing (/b) with all subdirectories (/s) only csv files.  Without more on the rest of the process its hard to say.

Contributor
Posts: 70

Re: how to get list of files available in Directory including sub folder in SAS

Thanks for quick replay.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 716 views
  • 1 like
  • 2 in conversation