Here’s a
SAS macro to Create and Remove a PC Directory… Often we ignore Notes and warning in the SAS log when we try to create/remove a directory that does/doesn’t exist…This macro first checks for the existence of the directory and then create/delete it or else put a message to the SAS log…try it out
/* Macro to Create a directory */ |
%macro CheckandCreateDir(dir); |
%let rc = %sysfunc(filename(fileref,&dir)) ; |
%if %sysfunc(fexist(&fileref)) %then |
%put The directory "&dir" already exists ; |
%if &sysrc eq 0 %then %put The directory &dir has been created. ; |
%else %put There was a problem while creating the directory &dir; |
%mend CheckandCreateDir ; |
/* Macro to Remove a PC directory */ |
options noxwait; /* Option noxwait specifies that the command processor automatically returns to the SAS session |
after the specified command is executed. You do not have to type EXIT... */ |
%let rc = %sysfunc(filename(fileref,&dir)) ; /* This sysfunc and the filename statements check for the existence of the directory */ |
%if %sysfunc(fexist(&fileref)) %then |
%put Removing directory &dir....; |
%sysexec rmdir /Q /S "&dir" ; /* Options /Q for quiet mode with no prompting and /S for removing sub directories */ |
%put The directory &dir and its sub-directories have been Deleted. ; |
%put There was a problem while Removing the directory &dir; |
%else %put The directory &dir does NOT EXIST; |
%sysexec - executes the command |
&sysrc - stores the return code of the above command sysexec |
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.