Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identify computer 3

Status
Not open for further replies.

bkclaw113

IS-IT--Management
Jun 10, 2002
71
US
I am trying to find a way to have SAS identify the computer name where my code is being executed, and then depending on what computer the code is running on I can have conditional statements to setup the correct paths for my libraries. This will allow the same code to be run either on my PC, my co-workers PC, or our SAS workstation through rsubmit.

Any ideas on how to get SAS to return the computer name or some other identifying information that would help me accomplish this?
 
bkclaw113,

I have a solution that will work on windows only. Perhaps with a few small changes you can get this to work on a UNIX os as well.

Try this code:
Code:
filename test pipe "set computername";

data yourinfo;
  infile test;
  length infostring $50
         cname      $40;
   input infostring $;
   Cname = scan(infostring,2,"=");
   call symput("compname",trim(cname));
run;

Remember that the DOS SET command can set something to a system variable such as path etc.. so be careful. Do not put the '=' sign in that fileref statement.

Here is what happends in the filename statement. Using the PIPE option, you are executing the system's DOS set command. (Try typing the DOS statement into a regular DOS window and the reults of that command is what this code tries to capture.)
Then have a data set read fileref using the INFILE statement along with the standard INPUT statement. You could use the _null_ dataset name, but I have written this so that you can check the results before you set the macro variable. Which is what the next two line do.
Using the SCAN function it reads the second part of the string returned. Then, using the CALL SYMPUT function it sets the results to a macro var named 'compname'. Remember use of the call symput only makes the macro var available after the RUN statement. (So you have to close this data step before you do any other processing.)

Hope that this helps you,
Klaz
 
Works just like you said it would. Thanks for the quick response.
 
Wow, cool method, never realised that you could do that. I would have just gone with some sort of XCOMMAND.
I'm giving you a star for that one! :)
 
Hi All,

I think u guys may know this very well. If you need to control u r SAS statements based on the operating environment you are working on the SAS automatic variables, SYSSCP & SYSSCPL wud be the ones to use.

Both, SYSSCP and SYSSCPL resolve to an abbreviation of the name of your operating environment.

A code example to show ways of deleting a temporary file "test" that may be across different platforms is given below:

%macro delfile;
%if /* HP Unix */&sysscp=HP 800 or &sysscp=HP 300
%then
%do;
X "rm test.TMP";
%end;
%else %if /* VMS */&sysscp=VMS
%then
%do;
X "DELETE test.TMP;*";
%end;
%else %if /* DOS-LIKE PLATFORMS */&sysscp=OS2 or &sysscp=WIN
%then
%do;
X "DEL test.TMP";
%end;
%else %if /* CMS */&sysscp=CMS
%then
%do;
X "ERASE test TEMP A";
%end;
%mend delfile;

Sarav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top