- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
~T
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let host= %SYSGET(envVarName);
PeterC
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
[pre]
data _null_;
infile 'hostname' pipe; /* pipe result of hostname comand */
input;
hostname=_infile_; /* _infile_ is the input buffer */
put hostname=;
run;
[/pre]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Patrick
Hmmm, somehow I think you posted in the wrong topic.
This is a 7 years old discussion 🙂
Daniel Santos @ www.cgd.pt
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
LOL! How did that happen? No idea how I've even got to such an old thread.