|
Hi guys,
I want a program with knowledge of its origin. Desperate to know its
roots, it's place inside its universe... Pondering on its genesis... :)
I'd like to know two things.
1. Can a program that is running determine what it is named?
2. Can a program that is running determine whether it is running from
itself or is being called by another program?
I'm on Windows, PC. An 8.2 that also works in 9.1.3 would be great
solution would be great. If it works in 9.1.3 but not in 8.2, I can live
with that.
Some further details:
I can get to know where a running proghram is located if I either assume
that it is opened in a fresh session or know its name, but I can no
longfer do with these restrictions.
For instance the following piece determines where a program is located
knowing its filename:
proc sql noprint;
select tranwrd(upcase(xpath),'DEMO_SYSINFO.SAS','')
into: FilePath
from dictionary.extfiles
where index(upcase(xpath),'DEMO_SYSINFO.SAS')
;
quit;
%put &FilePath;
The 'in a fresh session' restriction is there because every file you open
in the session has its place in the mentiopned dictionary table. Upon
opening a file in a fresh session, I know that the last one sorted on
fileref (obvviously, if there are other filerefs created in the program
itself it will only work before any of these occur in the code) will be
the right one as in this piece:
proc sql noprint;
create table tmp_f as select *
from dictionary.extfiles
order by fileref
;
quit;
data _null_;
set tmp_f end=last;
if last then call symput('FilePathName',trim(left(Xpath)));
run;
%put &FilePathName;
On the side: I'm not a proc sql expert, so if anyone wants to tell me how
I can do this last piece in one sql proc, that would be nice as well. I
need the last information to only process the last record when creating
the macrovariable. If somehow the proc sql could make me take only the
last one as well, that would be cool too (without having just the order by
in there and rely on the created macrovariable being the last one despite
having been processed for each one - which just seems... well, not nice).
Another on the side:
Mind the if last then in the piece of code above. Why is that faster than
the piece of code below (I would have expected the other way around):
data _null_;
set tmp_f end=last;
if last;
call symput('FilePathName',trim(left(Xpath)));
run;
Cheers,
Dirk
|