SAS Get Computer Name
I had a need to get the computer name in my SAS programs and assign it to a macro. Although there are many methods, I found this one the easiest (for working on MS Windows):
%let cname = “%sysget(computername)”;
There are other ways such as:
filename getinfo PIPE “hostname” ;
data _null_ ;
infile getinfo ;
input ;
put _infile_ ;
run ;
[as an aside, this works because 'hostname' is a command whereas trying to use 'computername' will not work because it is a system variable].
and
filename getcmd pipe ‘net config workstation’;
data theds(keep=theline);
length theline $200;
infile getcmd length=lenvar;
input @1 theline $varying. lenvar;
run;
[then parse out pieces you want]
and
%Put computername<%sysget(computername)>;
[again, parse out what you need]
[also, I don’t think this one works on Unix]


Reader Comments