From: RolandRB on
Is there no sashelp.v---- view for environment variables that gives a
list of environment variable names and their contents? I can't see one
among the list in sashelp. It's easy enough to write something for
this but I was kind of expecting to find it in sashelp.
From: RolandRB on
On Jul 28, 1:53 pm, RolandRB <rolandbe...(a)hotmail.com> wrote:
> Is there no sashelp.v---- view for environment variables that gives a
> list of environment variable names and their contents? I can't see one
> among the list in sashelp. It's easy enough to write something for
> this but I was kind of expecting to find it in sashelp.

So I wrote a macro but when I run it on my laptop which has Windows 7
64 bit on it with me having installed SAS/LE 4.1 in compatibility mode
I get the following. Forst the macro and then the message. Any ideas?


%macro env2ds(dsout);

%if not %length(&dsout) %then %let dsout=_env2ds;

filename _env2ds pipe 'set';

data &dsout;
length name $ 40 value $ 1000;
infile _env2ds;
input;
name=scan(_infile_,1,"=");
value=substr(_infile_,index(_infile_,"=")+1);
label name="Environment Variable Name"
value="Environment Variable Value"
;
run;

filename _env2ds clear;

%mend;

%env2ds;

NOTE: The infile _ENV2DS is:
Unnamed Pipe Access Device,
PROCESS=set,RECFM=V,LRECL=256

Stderr output:
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
Das Handle ist ungltig.
NOTE: 0 records were read from the infile _ENV2DS.
NOTE: The data set WORK._ENV2DS has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.27 seconds
cpu time 0.20 seconds


NOTE: Fileref _ENV2DS has been deassigned.
From: Richard A. DeVenezia on
On Jul 28, 12:42 pm, RolandRB <rolandbe...(a)hotmail.com> wrote:
> On Jul 28, 1:53 pm, RolandRB <rolandbe...(a)hotmail.com> wrote:
>
> > Is there no sashelp.v---- view for environment variables that gives a
> > list of environment variable names and their contents? I can't see one
> > among the list in sashelp. It's easy enough to write something for
> > this but I was kind of expecting to find it in sashelp.
>
> So I wrote a macro but when I run it on my laptop which has Windows 7
> 64 bit on it with me having installed SAS/LE 4.1 in compatibility mode
> I get the following. Forst the macro and then the message. Any ideas?
>

Roland,

Instead of using a macro and explicit filename and data steps, try
creating a DATA Step view that creates the pipe, reads it, parses the
name=value and outputs pertinent rows.

----------
data sasuser.venv / view=sasuser.venv;

length _fref $8 _buffer $500;

rc = filename(_fref, 'SET', 'PIPE');
_fid = fopen (_fref, 'S');

do while (fread(_fid) = 0);
rc = fget(_fid, _buffer, 500);
_eq = index (_buffer, '=');
if _eq > 1 then do;
name = substr(_buffer,1,_eq-1);
value = substr (_buffer, _eq+1);
OUTPUT;
end;
end;

rc = filename(_fref);

drop rc _:;
run;

data _null_;
set sasuser.venv;
put name= @35 value=;
run;
----------

With proper credentials, you could install the view as SASHELP.VENV.

Richard A. DeVenezia
http://www.devenezia.com
From: RolandRB on
On 28 Jul., 23:01, "Richard A. DeVenezia" <rdevene...(a)gmail.com>
wrote:
> On Jul 28, 12:42 pm, RolandRB <rolandbe...(a)hotmail.com> wrote:
>
> > On Jul 28, 1:53 pm, RolandRB <rolandbe...(a)hotmail.com> wrote:
>
> > > Is there no sashelp.v---- view for environment variables that gives a
> > > list of environment variable names and their contents? I can't see one
> > > among the list in sashelp. It's easy enough to write something for
> > > this but I was kind of expecting to find it in sashelp.
>
> > So I wrote a macro but when I run it on my laptop which has Windows 7
> > 64 bit on it with me having installed SAS/LE 4.1 in compatibility mode
> > I get the following. Forst the macro and then the message. Any ideas?
>
> Roland,
>
> Instead of using a macro and explicit filename and data steps, try
> creating a DATA Step view that creates the pipe, reads it, parses the
> name=value and outputs pertinent rows.
>
> ----------
> data sasuser.venv / view=sasuser.venv;
>
>   length _fref $8 _buffer $500;
>
>   rc = filename(_fref, 'SET', 'PIPE');
>   _fid = fopen (_fref, 'S');
>
>   do while (fread(_fid) = 0);
>     rc = fget(_fid, _buffer, 500);
>     _eq = index (_buffer, '=');
>     if _eq > 1 then do;
>       name = substr(_buffer,1,_eq-1);
>       value = substr (_buffer, _eq+1);
>       OUTPUT;
>     end;
>   end;
>
>   rc = filename(_fref);
>
>   drop rc _:;
> run;
>
> data _null_;
>   set sasuser.venv;
>   put name= @35 value=;
> run;
> ----------
>
> With proper credentials, you could install the view as SASHELP.VENV.
>
> Richard A. DeVeneziahttp://www.devenezia.com

Thanks for that but I am still wondering why it works on my machine at
work yet does not work on my Windows 7 laptop at home.
From: data _null_; on
On Jul 28, 4:01 pm, "Richard A. DeVenezia" <rdevene...(a)gmail.com>
wrote:
> On Jul 28, 12:42 pm, RolandRB <rolandbe...(a)hotmail.com> wrote:
>
> > On Jul 28, 1:53 pm, RolandRB <rolandbe...(a)hotmail.com> wrote:
>
> > > Is there no sashelp.v---- view for environment variables that gives a
> > > list of environment variable names and their contents? I can't see one
> > > among the list in sashelp. It's easy enough to write something for
> > > this but I was kind of expecting to find it in sashelp.
>
> > So I wrote a macro but when I run it on my laptop which has Windows 7
> > 64 bit on it with me having installed SAS/LE 4.1 in compatibility mode
> > I get the following. Forst the macro and then the message. Any ideas?
>
> Roland,
>
> Instead of using a macro and explicit filename and data steps, try
> creating a DATA Step view that creates the pipe, reads it, parses the
> name=value and outputs pertinent rows.
>
> ----------
> data sasuser.venv / view=sasuser.venv;
>
>   length _fref $8 _buffer $500;
>
>   rc = filename(_fref, 'SET', 'PIPE');
>   _fid = fopen (_fref, 'S');
>
>   do while (fread(_fid) = 0);
>     rc = fget(_fid, _buffer, 500);
>     _eq = index (_buffer, '=');
>     if _eq > 1 then do;
>       name = substr(_buffer,1,_eq-1);
>       value = substr (_buffer, _eq+1);
>       OUTPUT;
>     end;
>   end;
>
>   rc = filename(_fref);
>
>   drop rc _:;
> run;
>
> data _null_;
>   set sasuser.venv;
>   put name= @35 value=;
> run;
> ----------
>
> With proper credentials, you could install the view as SASHELP.VENV.
>
> Richard A. DeVeneziahttp://www.devenezia.com

Is there a reason you choose the FILE IO functions over a "regular"
INFILE/INPUT with FILEVAR option to avoid using the FILENAME
statement?

data sasuser.venv / view=sasuser.venv;
length name $32 value $1024;
command = 'SET';
infile dummy pipe filevar=command end=eof lrecl=2048;
do while(not eof);
input;
index = indexC(_infile_,'=');
if index then do;
name = substr(_infile_,1,index-1);
value = substr(_infile_,index+1);
output;
end;
end;
stop;
keep name value;
run;
data _null_;
set sasuser.venv;
put name= @35 value=;
run;