BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello everyone,
When testing one of our sas scripts on the development server we have to configure things slightly differently in the script (libnames pointing at different locations mainly), however it would be really useful if the script could automatically detect the hostname of the server it is currently running on. Does anyone know of a way to do this?
The help file plus google have not provided me with a solution yet.

Regards,
~Toby
10 REPLIES 10
deleted_user
Not applicable
HI,

I saw something about this yesterday actually. It seems v9.2 has a automatic macro variable called %syshostname

http://support.sas.com/documentation/cdl/en/whatsnew/62435/HTML/default/mcrolrefwhatsnew902.htm
RedPlanet
Obsidian | Level 7

Use &syshostname instead of %syshostname

 

% is used to identify a macro, but & is used to show the value of a macro variable.

 

Needless to say, it's important to know the difference between a macro and a macro variable, but most people just call them macros.

deleted_user
Not applicable
Sadly I believe we are using 9.1 (tried %put &syshostname; but that returned an error).

~T
deleted_user
Not applicable
read the environment variables. One will be the computername or hostname. It is platform dependant. Once you discover which, you can retrieve it with
%let host= %SYSGET(envVarName);

PeterC
DanielSantos
Barite | Level 11
Another way of doing that would be piping the result of hostname command:

data _null_;
infile 'hostname' pipe; /* pipe result of hostname comand */
hostname=_infile_; /* _infile_ is the input buffer */
put hostname=;
run;

this works on both UNIX and Windows systems.

Greetings from Portugal.

Daniel Santos at www.cgd.pt
data_null__
Jade | Level 19
You forgot one statement INPUT;
[pre]
data _null_;
infile 'hostname' pipe; /* pipe result of hostname comand */
input;
hostname=_infile_; /* _infile_ is the input buffer */
put hostname=;
run;
[/pre]
DanielSantos
Barite | Level 11
Yep. True.

Thanks.

Greetings from Portugal.

Daniel Santos at www.cgd.pt
Patrick
Opal | Level 21

Whenever I can influence things, then I make sure that directory structures are identical between environments. I don't think coding environment smart within individual scripts is a good approach. 

 

What's sometimes different is the "Root path". What I'm normally doing in such a case is to implement SAS macro variables in the Autoexec and so I keep all environment specific information in a single location for maintenance.

 

A libname statement would then look like:

libname myds "&data\subfolder1\subfolder2";

 

Where the "subfolders" are the part of the directory structure under my control and identical in all environments.

 

An alternative approach for libraries used in multiple programs would be, to define these libraries in SAS Metadata. This is again about keeping environment specific things in a central location and not spread out over many programs which becomes a maintenance nightmare in case something ever changes - and for example the host name will change when you upgrade to a current SAS version in a hopefully not too far future for you.

 

If you don't have the necessary level of access to modify the Autoexec or to change SAS Metadata then a 3rd option would be to create a %init macro with all these environment specific definitions. Store the macro code in a folder which is part of the SAS Autocall facility and then just call the macro always at the beginning of your programs.

DanielSantos
Barite | Level 11

Hi @Patrick

 

Hmmm, somehow I think you posted in the wrong topic.

 

This is a 7 years old discussion 🙂

 

Daniel Santos @ www.cgd.pt

Patrick
Opal | Level 21

@DanielSantos

LOL! How did that happen? No idea how I've even got to such an old thread.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 15844 views
  • 1 like
  • 5 in conversation