%macro drive(dir,ext);                                                                                                                  
%local filrf rc did memcnt name i ;      
 **%let count=0;                                                                                                                       
  /* 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 &name;   
%let val = %eval(&i+2);
# (&val) @15 "&name" attr= underline;
%end;                                                                                                                             
                                                                                                                        
%end;                                                                                                                                
                                                                                                                             
  /* Closes the directory and clear the fileref */                                                                                      
%let rc=%sysfunc(dclose(&did));                                                                                                       
%let rc=%sysfunc(filename(filrf));                                                                                                    
                                                                                                                                        
%mend drive;                                                                                                                            
                                                                                                                                        
%drive(c:\testing,csv);  
options mlogic symbolgen mprint;
%WINDOW showfiles
 ICOLUMN= 15 IROW= 10
 COLUMNS= 80 ROWS= 20
/* First parameter is the directory of where your files are stored. */                                                                  
/* Second parameter is the extension you are looking for.           */                                                                  
%drive(c:\testing,csv);  
%display showfiles;   1    %macro drive(dir,ext);
2    %local filrf rc did memcnt name i ;
3     **%let count=0;
4      /* Assigns a fileref to the directory and opens the directory */
5    %let rc=%sysfunc(filename(filrf,&dir));
6    %let did=%sysfunc(dopen(&filrf));
7
8    /* Make sure directory can be open */
9    %if &did eq 0 %then %do;
10   %put Directory &dir cannot be open or does not exist;
11   %return;
12   %end;
13
14      /* Loops through entire directory */
15   %do i = 1 %to %sysfunc(dnum(&did));
16
17        /* Retrieve name of each file */
18   %let name=%qsysfunc(dread(&did,&i));
19
20        /* Checks to see if the extension matches the parameter value */
21        /* If condition is true print the full name to the log        */
22   %if %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then %do;
23
24   %put &name;
25
26   %let val = %eval(&i+2);
27
28   # (&val) @15 "&name" attr= underline;
29
30   %end;
31
32   %end;
33
34     /* Closes the directory and clear the fileref */
35   %let rc=%sysfunc(dclose(&did));
36   %let rc=%sysfunc(filename(filrf));
37
38   %mend drive;
39
40   %drive(c:\testing,csv);
UTDtrainPrepped.csv
41
42   options mlogic symbolgen mprint;
43   %WINDOW showfiles
44    ICOLUMN= 15 IROW= 10
45    COLUMNS= 80 ROWS= 20
46   /* First parameter is the directory of where your files are stored. */
47   /* Second parameter is the extension you are looking for.           */
48   %drive(c:\testing,csv);
MLOGIC(DRIVE):  Beginning execution.
MLOGIC(DRIVE):  Parameter DIR has value c:\testing
MLOGIC(DRIVE):  Parameter EXT has value csv
MLOGIC(DRIVE):  %LOCAL  FILRF RC DID MEMCNT NAME I
MLOGIC(DRIVE):  %LET (variable name is COUNT)
MLOGIC(DRIVE):  %LET (variable name is RC)
SYMBOLGEN:  Macro variable DIR resolves to c:\testing
MLOGIC(DRIVE):  %LET (variable name is DID)
SYMBOLGEN:  Macro variable FILRF resolves to #LN00011
SYMBOLGEN:  Macro variable DID resolves to 1
MLOGIC(DRIVE):  %IF condition &did eq 0 is FALSE
SYMBOLGEN:  Macro variable DID resolves to 1
MLOGIC(DRIVE):  %DO loop beginning; index variable I; start value is 1; stop value is 3; by value is
      1.
MLOGIC(DRIVE):  %LET (variable name is NAME)
SYMBOLGEN:  Macro variable DID resolves to 1
SYMBOLGEN:  Macro variable I resolves to 1
SYMBOLGEN:  Macro variable NAME resolves to Q00066.xlsx
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
SYMBOLGEN:  Macro variable EXT resolves to csv
MLOGIC(DRIVE):  %IF condition %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) is FALSE
MLOGIC(DRIVE):  %DO loop index variable I is now 2; loop will iterate again.
MLOGIC(DRIVE):  %LET (variable name is NAME)
SYMBOLGEN:  Macro variable DID resolves to 1
SYMBOLGEN:  Macro variable I resolves to 2
SYMBOLGEN:  Macro variable NAME resolves to Q00080.xlsx
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
SYMBOLGEN:  Macro variable EXT resolves to csv
MLOGIC(DRIVE):  %IF condition %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) is FALSE
MLOGIC(DRIVE):  %DO loop index variable I is now 3; loop will iterate again.
MLOGIC(DRIVE):  %LET (variable name is NAME)
SYMBOLGEN:  Macro variable DID resolves to 1
SYMBOLGEN:  Macro variable I resolves to 3
SYMBOLGEN:  Macro variable NAME resolves to UTDtrainPrepped.csv
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
SYMBOLGEN:  Macro variable EXT resolves to csv
MLOGIC(DRIVE):  %IF condition %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) is TRUE
MLOGIC(DRIVE):  %PUT &name
SYMBOLGEN:  Macro variable NAME resolves to UTDtrainPrepped.csv
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
UTDtrainPrepped.csv
MLOGIC(DRIVE):  %LET (variable name is VAL)
SYMBOLGEN:  Macro variable I resolves to 3
NOTE 137-205: Line generated by the invoked macro "DRIVE".
1       **
        --
        22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, #, +, /, //, @,
              COLOR, COLOUR, COLUMNS, GROUP, HELP, ICOLUMN, IROW, KEY, KEYS, MENU, MENUS, ROWS.
SYMBOLGEN:  Macro variable VAL resolves to 5
SYMBOLGEN:  Macro variable NAME resolves to UTDtrainPrepped.csv
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
NOTE: Line generated by the invoked macro "DRIVE".
1       **
        --
        200
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR: %WINDOW statement not processed due to errors.
MLOGIC(DRIVE):  %DO loop index variable I is now 4; loop will not iterate again.
MLOGIC(DRIVE):  %LET (variable name is RC)
SYMBOLGEN:  Macro variable DID resolves to 1
MLOGIC(DRIVE):  %LET (variable name is RC)
MLOGIC(DRIVE):  Ending execution.
49   %display showfiles;
ERROR: Unable to open window macro file SHOWFILES. 
						
					
					... View more