-
Notifications
You must be signed in to change notification settings - Fork 8
/
curdir.sas
66 lines (54 loc) · 2.65 KB
/
curdir.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
%macro curdir
/*----------------------------------------------------------------------
Returns (optionally changes) the current SAS directory physical name
----------------------------------------------------------------------*/
(curdir /* Optional new current directory */
)
;
/*----------------------------------------------------------------------
Usage:
When a path is provided it will first change the current directory to
that directory. It returns the current SAS directory physical name,
after any optional change.
%put %curdir is the current directory.;
%put %curdir(~/sas) is the NEW current directory.;
%let here=%curdir;
%put Changed current directory to its parent directory %curdir(..);
------------------------------------------------------------------------
Notes:
It will open a fileref to find the current directory. Using that method
will not write a message to the log.
But when you want to change directories it will call the DLGCDIR()
function which will always write a message to the log.
The macro variable SYSRC will be set. 0 means success and any other
value is the error code from DLGCDIR() function call.
Based on code from Tom Hoffman.
-----------------------------------------------------------------------
History:
11MAR99 TRHoffman Creation - with help from Tom Abernathy.
06DEC00 TRHoffman Used . notation to reference current directory as
suggested by Fan Zhou.
19MAR2023 abernt Added option to change the directory using DLGCDIR().
----------------------------------------------------------------------*/
%local fr rc ;
%*---------------------------------------------------------------------
Set the SYSRC macro variable to default as success
----------------------------------------------------------------------;
%if not %symexist(sysrc) %then %global sysrc;
%let sysrc=0;
%*---------------------------------------------------------------------
When a path is provided use DLGCDIR() to change current directory.
Pass the return code to SYSRC macro variable.
----------------------------------------------------------------------;
%if %length(&curdir) %then %let sysrc=%sysfunc(dlgcdir(&curdir));
%*---------------------------------------------------------------------
Open a fileref pointing at the current directory and get its path.
----------------------------------------------------------------------;
%let rc = %sysfunc(filename(fr,.));
%let curdir = %sysfunc(pathname(&fr));
%let rc = %sysfunc(filename(fr));
%*---------------------------------------------------------------------
Return the current directory as the output of the macro.
----------------------------------------------------------------------;
&curdir
%mend curdir;