%let filepath=C://;* Filepath to pick up the files;
%macro extract(dir=, ext=);
%let filrf=mydir;
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));
%let memcnt=%sysfunc(dnum(&did));
%do i = 1 %to &memcnt;
%let memname = %qsysfunc(dread(&did, &i));
%let fid = %sysfunc(mopen(&did, &memname));
%let extname=%qscan(%qsysfunc(dread(&did,&i)),-1,.); /* Returns the extension from each file */
/* Returns the file name portion */
%let name1=%qscan(%qsysfunc(dread(&did,&i)),1,.); /* filename with yymmdd */
%let name2=%substr(&name1,1,(%length(&name1)-6)); /* filename without yymmdd */
/* Checks to see if file contains an extension */
%if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&ext) %then %do;
%if (%qupcase(&extname) eq %qupcase(&ext)) and ("&name1" ne "") %then %do;
/* if condition TRUE then execute SAS statement......*/
%put user;
/* export filenames in dataset */
data a;
format file $20. file2 $20.;
no = &i.;
file = "&name1.";
file2 = "&memname.";
run;
data a_all;
%if &i = 1 %then %do;
set a;
%end;
%else %do;
set a_all a;
%end;
run;
%end;
%end;
%end;
%let rc=%sysfunc(dclose(&did));
%mend;
%extract(dir=&filepath, ext=/file extension/)
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.