Date: Tue, 14 Nov 2006 15:29:17 -0500
Reply-To: Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Subject: Re: Chance to Make SAS-L History: Did You Know That...
Content-Type: text/plain; charset=ISO-8859-1
Hi Ron
"Did you know" ...
%sysfunc( getoption( set ));
returns only environment variables established through config
file -set statements, and run-time option set= .... ; statements
You can retrieve a complete set of environment variables available
to the SAS session with some code I published in the SUGI tutorial
Paper 237-31: Peter Crawford
The Personal Touch: Control Your Environment as a SASĀ® User
http://www2.sas.com/proceedings/sugi31/237-31.pdf
The advantage is that, for those cases where an environment variable
passes values when present, but may not be present, signifying blank
or "use defaults", retrieving a non-existant env.var with %sysget()
produces a Warning, that would "pollute" the saslog of a production
job. The following technique helps avoid that Warning.
It also provides some interesting insight to your platform;-)
The (platform independant) code is so brief I'll reproduce it here
DATA evars( KEEP= name value COMPRESS= yes ) ;
LENGTH name $40 value $2000 ;
FILENAME envs PIPE 'set ' LRECL= 2000;
INFILE envs TRUNCOVER DSD DLM= '=' COL= col ;
INPUT name;
IF name ne ' ' ;
value = SUBSTR( _infile_ || ' ', col ) ;
RUN;
FILENAME envs CLEAR;
Then retrieve the non-existant env.var WORK like
%let eName1={empty};
*ensuring the macro var exists before (not)assigning ;
proc sql noprint ;
select name, trim(value) into :eName1, :eVar1
from eVars
where name = 'WORK' ;
%put found &sqlobs env.vars named WORK starting &eName1;
quit ;
You get no Warning if env.var WORK is not present but
regular method ........;
%let eName2 = %sysget(WORK) ;
generates that warning
Regards
Peter Crawford
http://www.technical-event.co.uk
On Tue, 14 Nov 2006 10:41:17 -0500, Fehd, Ronald J. (CDC/CCHIS/NCPHI)
<rjf2@CDC.GOV> wrote:
>> From: Don Henderson
>> Did you know that you can use the %sysfunc macro with the
>> getoption function to access the value of a single option, e.g.,
>>
>> %let source = %sysfunc(getoption(source));
>
>to fetch the values of environment variables (e-vars)
>
>%let sasroot = %sysget(sasroot);
>%Put sasroot<&sasroot.>;
>
>to get a list of all e-vars and their values:
>%Put %sysfunc(getoption(set));
>
>Ron Fehd the e-var maven CDC Atlanta GA USA RJF2 at cdc dot gov