Tuesday, 5 February 2013

SAS Macro to Create a folder using SAS programming

SAS Macro to Create a folder using SAS programming


type the folder name you want to be created instead of dir then first compile the ,acro and run the macro.


%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 ;

3 comments:

  1. Hey Nitin,
    Please provide me with some basic as well as important questions related to SAS Macros

    ReplyDelete
  2. Here i had a chance to create a folder using a sas program thanks for this information.
    Regards,
    sas training in Chennai

    ReplyDelete
  3. %Macro Verifica_Lib(Libreria,Ruta);
    Data _Null_;
    Call Symput('Destino',&Ruta||Compress('&Libreria'));
    Run;
    %Put &Destino;
    %If (%SysFunc(LibRef(&Libreria))) Ne 0 %Then %Do;
    %Put Verificando existencia de libreria;
    %Put La libreira &Libreria No Existe;
    %Put Se procederaa crearla;
    Options DLCreateDir;
    LibName &Libreria "&Destino";
    %End;
    %Else %Do;
    %Put Verificando existencia de libreria;
    %Put La libreira &Libreria existe;
    %Put Se continuara el proceso;
    %End;
    %Error_Sas(Verificacion de Libreria local);
    %MEnd Verifica_Lib;

    ReplyDelete