Date: Fri, 9 Mar 2001 16:49:47 -0500
Reply-To: Tim Williams <williamstim@PRAINTL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Tim Williams <williamstim@PRAINTL.COM>
Subject: Re: How to get userid when running SAS
Thanks to Peter, David and Nick for helping me out. I used the code below,
then assigned the USERNAME or USERID environment vars. to a macro var. for
use in later decision making.
if label in('USERNAME','USERID') then call symput('person',varvalue);
This works for both local submits (if my user had, in autoexec.bat,
specified SET USERID=williamsTim) or submits to my remote server, where
USERNAME is set.
Thanks - and have a great weekend!
Tim
On Fri, 9 Mar 2001 11:56:51 +0100, Peter Crawford <peter.crawford@DB.COM>
wrote:
>A variation on David Johnson's data step, to load all environment variable
(set) information with generated varnames ;
>(tested on winNT sas v6.12
> and os390 v8.1 !!!)
>It worked fine on winNT
>FileName ZZZSETUP Pipe 'set';
>Data envs(drop=string);
> Length VARNAME $8 LABEL $40 VARVALUE $80 string $200 ;
> Infile ZZZSETUP TruncOver END = EOF length=l;
> Input STRING $varying200. l;
> label = scan( string, 1, '=' );
> VARname = 'Env' !! left( put( _n_, 3. ) );
> VARVALUE = Substr( STRING, Index( STRING, '=') + 1 );
>Run;
>FileName ZZZSETUP Clear;
>
>I wasn't expecting the os390 to have any environment variables.
>But it produced a message to indicate it was "trying"
>
>NOTE: The infile ZZZSETUP is:
> Pipe command=set
>
>WARNING: Pipe command stopped by signal 9.
>
>So I don't need to find any explanation for this "signal 9" !!!
>
>
>
>
>
>Datum: 09/03/2001 09:19
>An: SAS-L@listserv.uga.edu
>
>
>
>
>Antwort an: DavidJohnson@halifax.co.uk
>
>Betreff: Re: How to get userid when running SAS
>Nachrichtentext:
>
>
>Tim's question is posted below:
>
>Tim,
>
>A number of solutions have now been proposed to this question, and it is
>beginning to take me off the mainstream direction of my project, so please
>don't expect anything elegant in the solutions.
>
>Many people have said: just read the environment variable. I found two
>platforms here where those values were not set. Here is the result:
>
>WARNING: The argument to macro function %SYSGET is not defined as a system
>variable.
>27 %Let LanName = %SysGet( I_Dont_exist);
>
>My AF application cannot have any warnings except those caused by User
>misuse or data problems. A warning in any submit block is flagged to the
>user as a system problem. Consequently, if the env variable may not exist,
>I needed to design something more robust.
>
>
>I wanted to know what variables were set for two different platforms and
ran
>the following code:
>
>FileName ZZZSETUP Pipe 'set';
>
>Data ENVVARS;
>Run;
>
>Data _NULL;
> Length VARNAME $8 LABEL $40 VARVALUE $80;
> Infile ZZZSETUP TruncOver END = EOF;
> Call Execute( 'Data ENVVARS( ');
> Call Execute( 'Label = "Operating system environment variables");');
> Call Execute( 'Set ENVVARS;');
> Input @1 STRING $Char80.;
> STRING = CompBl( Compress( STRING, '"') );
> VARNAME = Substr( STRING, 1, Index( STRING, '=') - 1 );
> LABEL = Substr( STRING, 1, Index( STRING, '=') - 1 );
> VARVALUE = Substr( STRING, Index( STRING, '=') + 1 );
> If VARNAME Eq: 'PROCESSOR_' Then VARNAME = Substr( LABEL, 11, 8);
> Call Execute( VARNAME || ' = "' || VARVALUE || '";');
> Call Execute( 'Label ' || VARNAME || ' = "' || LABEL || '";');
> Call Execute( 'Run;');
>Run;
>Run;
>
>FileName ZZZSETUP Clear;
>
>For one platform it generates a data set with 27 variables, on another it
>generates a lot fewer. It isn't 'flash' code, but it seemed robust until I
>shared it with Nick Paszty yesterday. He found that an environment
variable
>was set that replicated the SAS Install option, ie it was a concatenated
>series of directory names enclosed in double quotes. The COMPRESS function
>removes those quotes and should overcome its problem in running on his
>platform BUT
>
>. It doesn't capture those parts of the environment variable which
are
>reported on second and subsequent lines of the PIPE file.
>
>As I said to Nick, I can get that value with SysFunc on GetOption, so I'm
>not going to try to capture the value in this data step, but I will try to
>make the code robust enough to deal with a different result. Sometime
after
>the sun rises over America, I expect he'll let me know how it worked.
>
>
>Some other things:
>. It's written for 6.12, no apologies, it just is.
>. Consequently environment names longer than 8 characters are
>truncated
>. Some env values will appear to duplicate in the first 8 characters,
>which is why I included the 'PROCESSOR_' patch for my NT machine to capture
>the part of the name that was discriminant, and probably a better
>description. Meantime, the variable label will return up to 40 characters
>of the environment variable name.
>. Maximum environment value is capped at 80 characters by my code.
>Even that is rather long for the values I am interested in.
>. Yes, it could be done in one pass
>. Yes it could be done more elegantly
>. Yes it would then take a piece of time to write that code and test
>it
>. That time is available at a price higher than trimming 1 second off
>a two second run time!
>
>It's offered as it stands.
>
>If anyone wants to share some peculiar environment variable on your system
>that causes it to crash or perform in an unexpected manner, then I'd like
to
>hear about it.
>
>
>Regards
>
>David
>
>
>
>SAS-L Digest - 8 Mar 2001 - Special issue (#2001-306)
>
>Date: Thu, 8 Mar 2001 15:03:18 -0500
>From: Tim Williams <williamstim@PRAINTL.COM>
>Subject: Re: How to get userid when running SAS
>
>This discussion raises some interesting points that I would like to
>incorporate into my own work.
>
>How can I determine what environment variables are set when submit a job to
>our NT SAS 6.12 server? Say I just want to PIPE them in and take a look
>at 'em? Is there some way I can display all those that are set on the
>server when my job executes
>
>The SAS code I am writing will take different branches depending on who
>submits it, so I would like to grab the login ID of the user submitting the
>code and make decisions based on that.
>
> If a USERID or LOGIN_ID is not available, what do I have to tell my
>friendly NT sysadmin to do so it will be available?
>
>TIA!
>
>Tim
>
>williamsTim@praintl.com
>
>
>** ##*
>
>David Johnson
>This message is attributable to the sender and does not necessarily reflect
>the view of Halifax Group plc or its subsidiaries.
|