Get PC Files From a folder

Getting the P/C file names in a folder can assist in finding out if a specific file exists or generating a macro variable parameter list to complete a variety of functions on each file. The file type is an important part of the file selection criteria and is a parameter to the GET_PC_FILES_IN_FOLDER macro

To see how to gererate and use a macro variable click here Create macro variable array from SAS variable

Getting the P/C file names in a folder and all of its sub-folders click here Get PC files from a folder and all sub-folders

SAS Fifth Dimension Macro-GET_PC_FILES_IN_FOLDER

%MACRO GET_PC_FILES_IN_FOLDER(DIRNAME,TYP)     ;
%PUT %STR(----------->DIRNAME=&DIRNAME)        ;
%PUT %STR(----------->TYP=&TYP)                ;
DATA WORK.DIRFILES                             ;
     RC=FILENAME("DIR","&DIRNAME")             ;
     OPENFILE=DOPEN("DIR")                     ;
     IF OPENFILE>0 THEN DO                     ;
        NUMMEM=DNUM(OPENFILE)                  ;
        DO II=1 TO NUMMEM                      ;
           NAME=DREAD(OPENFILE,II)             ;
           OUTPUT                              ;
        END                                    ;
     END                                       ;
     KEEP NAME                                 ;
RUN                                            ;
PROC SORT                                      ;
     BY DESCENDING NAME                        ;
%IF &TYP^=ALL %THEN %DO                        ;
     WHERE  INDEX(UPCASE(NAME),UPCASE(".&TYP"));
%END                                           ;
RUN                                            ;
%MEND   GET_PC_FILES_IN_FOLDE                  ;