Sas Macro To Create Delete A Directory

  • Uploaded by: SASTechies
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sas Macro To Create Delete A Directory as PDF for free.

More details

  • Words: 331
  • Pages: 3
SAS macro to Create / Remove a PC Directory... 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); options noxwait; %local rc fileref ; %let rc = %sysfunc(filename(fileref,&dir)) ; %if %sysfunc(fexist(&fileref)) %then %put The directory "&dir" already exists ; %else %do ; %sysexec mkdir "&dir" ; %if &sysrc eq 0 %then %put The directory &dir has been created. ; %else %put There was a problem while creating the directory &dir; %end ; %mend CheckandCreateDir ;

/* Macro to Remove a PC directory */ %macro RemoveDir(dir); 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... */

%local rc fileref ; %let rc = %sysfunc(filename(fileref,&dir)) ; /* This sysfunc and the filename statements check for the existence of the directory */ %if %sysfunc(fexist(&fileref)) %then %do; %put Removing directory &dir....; %sysexec rmdir /Q /S "&dir" ; /* Options /Q for quiet mode with no prompting and /S for removing sub directories */ %if &sysrc eq 0 %then %put The directory &dir and its sub-directories have been Deleted. ; %else %put There was a problem while Removing the directory &dir; %end;

%else %put The directory &dir does NOT EXIST; %mend RemoveDir ;

/* %sysexec - executes the command &sysrc - stores the return code of the above command sysexec */ You might also like: • • • •

Ways to Count the Number of Obs in a dataset and pass it into a macro variable... SAS macro to reorder dataset variables in alphabetical order SAS Interview Questions and Answers(1) SAS Interview Questions and Answers(2)

Read full article @ http://sastechies.blogspot.com/2009/11/sas-macro-to-remove-pc-directory.html

Related Documents


More Documents from "Shashank Dev Sondhi"