From: RolandRB on
I want to get a Windows system environment variable to resolve but I
have this problem that to get it to resolve you have to put a "%" at
front and back so sas thinks you are trying to run a macro of that
name which I am not. How do I get round this in sas, let's say for
%username%?

From: keith.x.vossberg on
On Feb 15, 2:13 pm, "RolandRB" <rolandbe...(a)hotmail.com> wrote:
> I want to get a Windows system environment variable to resolve but I
> have this problem that to get it to resolve you have to put a "%" at
> front and back so sas thinks you are trying to run a macro of that
> name which I am not. How do I get round this in sas, let's say for
> %username%?

Roland,
This is how I capture environment variables:

%let user=%upcase(&sysuserid); *Get user id;
%let comp=%sysget(computername); *Capture name of comupter;

Keith

From: RolandRB on
On 15 Feb, 20:26, keith.x.vossb...(a)us.hsbc.com wrote:
> On Feb 15, 2:13 pm, "RolandRB" <rolandbe...(a)hotmail.com> wrote:
>
> > I want to get a Windows system environment variable to resolve but I
> > have this problem that to get it to resolve you have to put a "%" at
> > front and back so sas thinks you are trying to run a macro of that
> > name which I am not. How do I get round this in sas, let's say for
> > %username%?
>
> Roland,
> This is how I capture environment variables:
>
> %let user=%upcase(&sysuserid); *Get user id;
> %let comp=%sysget(computername); *Capture name of comupter;
>
> Keith

Thanks but I can not allow warning messages in my log from %sysget()
for when the environment variable is not defined so I have to run the
system command to echo it and capture the results. I don't like the
solution I have come up with but it appears to work. Search for
"outdir" in the macro code below:

http://www.datasavantconsulting.com/roland/spectre/macros/openrep.sas

It calls %readpipe and %dequote which you can link to below:

http://www.datasavantconsulting.com/roland/spectre/macros/readpipe.sas
http://www.datasavantconsulting.com/roland/spectre/macros/dequote.sas

I was hoping that there would be a more elegant way of doing it.

From: Martin Gregory on
On 02/15/2007 09:23 PM, RolandRB wrote:
> On 15 Feb, 20:26, keith.x.vossb...(a)us.hsbc.com wrote:
>> On Feb 15, 2:13 pm, "RolandRB" <rolandbe...(a)hotmail.com> wrote:
>>
>>> I want to get a Windows system environment variable to resolve but I
>>> have this problem that to get it to resolve you have to put a "%" at
>>> front and back so sas thinks you are trying to run a macro of that
>>> name which I am not. How do I get round this in sas, let's say for
>>> %username%?
>> Roland,
>> This is how I capture environment variables:
>>
>> %let user=%upcase(&sysuserid); *Get user id;
>> %let comp=%sysget(computername); *Capture name of comupter;
>>
>> Keith
>
> Thanks but I can not allow warning messages in my log from %sysget()
> for when the environment variable is not defined so I have to run the
> system command to echo it and capture the results. I don't like the
> solution I have come up with but it appears to work. Search for
> "outdir" in the macro code below:
>
> http://www.datasavantconsulting.com/roland/spectre/macros/openrep.sas
>
> It calls %readpipe and %dequote which you can link to below:
>
> http://www.datasavantconsulting.com/roland/spectre/macros/readpipe.sas
> http://www.datasavantconsulting.com/roland/spectre/macros/dequote.sas
>
> I was hoping that there would be a more elegant way of doing it.
>

using the sysget() function in a data step produces only a note if the
environment variable does not exist.

Another alternative, assuming that there is no exist() function in
windows to check for an environment is to issue the command set, which
lists all environment vars and their values. Parse the output via a pipe
with a datastep and you can both check existence and read the value if
it exists in one go.

regards,

Martin
From: RolandRB on
On 15 Feb, 22:43, Martin Gregory <grego...(a)t-online.de> wrote:
> On 02/15/2007 09:23 PM, RolandRB wrote:
>
>
>
>
>
> > On 15 Feb, 20:26, keith.x.vossb...(a)us.hsbc.com wrote:
> >> On Feb 15, 2:13 pm, "RolandRB" <rolandbe...(a)hotmail.com> wrote:
>
> >>> I want to get a Windows system environment variable to resolve but I
> >>> have this problem that to get it to resolve you have to put a "%" at
> >>> front and back so sas thinks you are trying to run a macro of that
> >>> name which I am not. How do I get round this in sas, let's say for
> >>> %username%?
> >> Roland,
> >> This is how I capture environment variables:
>
> >> %let user=%upcase(&sysuserid); *Get user id;
> >> %let comp=%sysget(computername); *Capture name of comupter;
>
> >> Keith
>
> > Thanks but I can not allow warning messages in my log from %sysget()
> > for when the environment variable is not defined so I have to run the
> > system command to echo it and capture the results. I don't like the
> > solution I have come up with but it appears to work. Search for
> > "outdir" in the macro code below:
>
> >http://www.datasavantconsulting.com/roland/spectre/macros/openrep.sas
>
> > It calls %readpipe and %dequote which you can link to below:
>
> >http://www.datasavantconsulting.com/roland/spectre/macros/readpipe.sas
> >http://www.datasavantconsulting.com/roland/spectre/macros/dequote.sas
>
> > I was hoping that there would be a more elegant way of doing it.
>
> using the sysget() function in a data step produces only a note if the
> environment variable does not exist.

I'm using it with a %sysget() call and I get a warning message if it
does not exist.

> Another alternative, assuming that there is no exist() function in
> windows to check for an environment is to issue the command set, which
> lists all environment vars and their values. Parse the output via a pipe
> with a datastep and you can both check existence and read the value if
> it exists in one go.

So far my method is easiest, Thanks for your suggestions.