15.4.08

Accessing the current working directory where the file containing the SAS code is stored


Compiled by Prajitha Nair


Let the SAS editor containing the code be KR-PH-XXX-SAS-Init.sas and it is stored in a folder named SAS Programs_Final.


The following %let statements assigns the folder and editor names to macro variables pgmfld and pgm respectively.


%let pgmfld = SAS Programs_Final; /*Folder in which SAS code is stored*/
%let pgm= KR-PH-XXX-SAS-Init.sas; /*Name of the program editor*/


The following macro is then used to extract the path of the editor from sashelp.vextfl and determine the path of the folder as “dir1” and of the editor as “dir2”.


%macro filePath;
%global fpath maxRef;

proc sql noprint;
select xpath into :fPath
from sashelp.vextfl where xpath ? "&pgm";
quit;


%let fpath = %trim(&fpath);
%put &fpath;
%global dir1 dir2 pgm1 pgmfld1;
%let pgm1 =%trim(&pgm);
%let pgmfld1= %trim(&pgmfld);


data _null_;
x=length("&fpath")-length("&pgm1");
y=length("&fpath")-length("&pgm1")-length("&pgmfld1")-1;
call symput("dir2" ,trim(substr("&fpath",1,x)));
call symput("dir1" ,trim(substr("&fpath",1,y)));
run;


%mend filePath;


This macro helps in determining the path of the code and enables the code to be executed in any computer provided the SAS code is saved within a folder and the naming conventions are followed as above.

No comments: