Hello,
I have a problem with one of my macros using SAS 9.22 on Windows 7. I amrunning my programmes on different computers in different directories. ThereforeI wrote a little macro which checks the computer’s hostname and according tothis name assigns my library to a certain directory. I do the following to putthe hostname into a macro variable:
FILENAME h PIPE 'hostname';
DATA_NULL_;
INFILE h;
INPUT;
PUT _infile_ ;
CALL SYMPUT('current_com',TRIM(LEFT(_infile_)));
RUN;
This works with Win XP and SAS 9.22. Here is what thelog says:
NOTE:The infile H is:
Unnamed Pipe Access Device,
PROCESS=hostname,RECFM=V,LRECL=256
myhostname
NOTE: 1record was read from the infile H.
The minimum record length was 10.
The maximum record length was 10.
NOTE:DATA statement used (Total process time):
real time 0.09 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
However, on Windows 7 I obtain:
NOTE:The infile H is:
Unnamed Pipe Access Device,
PROCESS=hostname,RECFM=V,LRECL=256
NOTE: 0records were read from the infile H.
NOTE:DATA statement used (Total process time):
real time 0.31 seconds
cpu time 0.04 seconds
So apparently the hostname couldn’t be read. If I type ‘hostname’in the windows console I get the hostname as expected.
P.S. I apologise if this isn't the correct forum section. It seems most appropriate
not having win7, I couldn't predict that result.
Similarly %sysget(hostname) failed on my win-vista as the %hostname% does not exist here either.
For that reason I had developed the step to load all current env-vars.
Your experience on win-7 matches the usage note at
http://support.sas.com/kb/41/863.html
Problem Note 41863: Problems using the PIPE engine in Windows 7 x64 operating system
Perhaps the suggestions will work for you
good luck
peter
Out of curiosity: what happens when you type hostname in the Windows 7 command prompt?
If all you are doing here is gather the hostname why not just use the automatic macro variable syshostname?
Because I wasn't aware of this macro variable :smileysilly: Using syshostname works, thanks! I still would like to find out what is wrong with my original code, though. Maybe my response to Peter.C gives a lead...
It gives me the hostname, assuming that what you call 'command prompt' is what I called 'windows console' (cmd.exe).
if the FriedEgg suggestion above provides the wrong information for &SYSHOSTNAME, here is some testing code to load ALL environment variables into SAS table named work.EVARS.
%put &syshostname;
%put %sysget(hostname);
data evars ;
filename envs pipe 'set' ;
length name $50 value $1024 check $6 ;
format name $20. value $100. ;
infile envs truncover length=l lrecl=10000 col=c dlm= '=';
input name @ ;
if c>=l then value=' ';
else value = substr( _infile_, c ) ;
check = scan( 'ok#wider!', (( l-c) > 1024)+1, '#' ) ;
run ;
Probably the full list of these will vary for each op.sys and possible each install. I expect you will see some name that is consistently correct.
Just load the one you want with
%let current_com = %sysget(correct_environment_variable_name) ;
Many thanks for your reply. Unfortunately your code doesn’t work. First, %put %sysget(hostname); gives a warning on XP as well as on Win7:
WARNING: The argument to macro function %SYSGET is not defined as a system variable.
The datastep afterwards works on XP but not on Win 7. The error message is similar to the one in my original post:
NOTE:The infile ENVS is:
Unnamed Pipe Access Device,
PROCESS=set,RECFM=V,LRECL=10000
Stderr output:
The handle is invalid.
The handle is invalid.
(More handle invalid lines)
The handle is invalid.
NOTE: 0 records were read from the infile ENVS.
NOTE: The data set WORK.EVARS has 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.14 seconds
user cpu time 0.01 seconds
system cpu time 0.03 seconds
Maybe I should mention that, unlike XP, the Win 7 installation is 64 bit.
not having win7, I couldn't predict that result.
Similarly %sysget(hostname) failed on my win-vista as the %hostname% does not exist here either.
For that reason I had developed the step to load all current env-vars.
Your experience on win-7 matches the usage note at
http://support.sas.com/kb/41/863.html
Problem Note 41863: Problems using the PIPE engine in Windows 7 x64 operating system
Perhaps the suggestions will work for you
good luck
peter
Thanks for pointing me to the usage note. Pinning SAS to the task bar resolves the issue.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.