BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello dears SAS users
I have a library called mylib with .png inside and i want to delete all the png picture of this library with a code like
data _null_ ;
call system("cd &pathUser. ; pwd ; mkdir &userID.;") ;
run ;
but i don't know the code to do it
Could you help me please ?
thank you
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Have a look at the SAS documentation and your particular SAS OS companion guide. The FILENAME PIPE engine provides a means to generate commands.

Scott Barry
SBBWorks, Inc.

SAS Support website and hosted Documentation:
http://support.sas.com/documentation/onlinedoc/base/index.html

Example for Unix:
http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/pipe.htm
Oleg_L
Obsidian | Level 7
Hello.
You can try this code

%macro dirclear(dir=d:\test,ext=xls);
%let ext=%upcase(&ext);
%let dlm=\;
%let filrf=;
%let rc=%sysfunc(filename(filrf,"&dir"));
%let did=%sysfunc(dopen(&filrf));
%let lstname=;
%let memcount=%sysfunc(dnum(&did));
%if &memcount > 0 %then %do;
%do i=1 %to &memcount;
%let lstname=%sysfunc(dread(&did,&i));
%let file=&dir&dlm&lstname;
%let ln=%length(&lstname);
data _null_;
c="&lstname"; c1=reverse(c); ln1=index(c1,'.'); ln=&ln-ln1+2; ln3=ln1-1;
ln4=upcase(substr(c,ln,ln3));
call symput('ln2',trim(left(ln4)));
run;
%if &ln2=&ext or &ext= %then %do;
%let rb=%sysfunc(filename(fname,"&file"));
%let rv=%sysfunc(fdelete(&fname));
%end; %end; %end;
%let rc=%sysfunc(dclose(&did));
%mend dirclear;

%let path=%sysfunc(pathname(mylib));
%dirclear(dir=&path,ext=png)
Oleg_L
Obsidian | Level 7
You can also use statements:

%let path=%sysfunc(pathname(mylib));
systask command
"del ""&path.\*.png"""
wait taskname="deleting";
deleted_user
Not applicable
Thank yoy
oleg, i prefer your second solution 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1900 views
  • 0 likes
  • 3 in conversation