« Pie Charts - a reminder | Main | Removing the SAS Enhanced Editor “Command===>” »

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]

 

 

Posted on Monday, March 31, 2008 by Registered CommenterJared in | CommentsPost a Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>