From: RolandRB on
On Jul 31, 5:29 am, Tom Abernathy <tom.aberna...(a)gmail.com> wrote:
> You can simplify the input code by using the = as a delimiter on the
> INFILE statement.
>
> data envars;
>    length name $32 value $1024;
>    command = 'SET';
>    infile dummy pipe filevar=command dlm='=' truncover end=eof
> lrecl=2048;
>    do while(not eof);
>       input name value $char1024. ;
>       output;
>    end;
>    stop;
>    keep name value;
> run;
>
> On Jul 29, 7:29 am, "data _null_;" <datan...(a)gmail.com> wrote:
>
> > 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;

I still get the "invalid file handle" error message if I avoid using a
filename statement.
From: data _null_; on
On Jul 30, 10:29 pm, Tom Abernathy <tom.aberna...(a)gmail.com> wrote:
> You can simplify the input code by using the = as a delimiter on the
> INFILE statement.
>
> data envars;
>    length name $32 value $1024;
>    command = 'SET';
>    infile dummy pipe filevar=command dlm='=' truncover end=eof
> lrecl=2048;
>    do while(not eof);
>       input name value $char1024. ;
>       output;
>    end;
>    stop;
>    keep name value;
> run;
>
> On Jul 29, 7:29 am, "data _null_;" <datan...(a)gmail.com> wrote:
>
>
>
> > 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;- Hide quoted text -
>
> - Show quoted text -

Where if the value if the ENV variable contains an equal sign?

options set=tom 'this has = equal sign and another =';
From: Tom Abernathy on
On Jul 31, 7:25 am, "data _null_;" <datan...(a)gmail.com> wrote:
> On Jul 30, 10:29 pm, Tom Abernathy <tom.aberna...(a)gmail.com> wrote:
>
>
>
>
>
> > You can simplify the input code by using the = as a delimiter on the
> > INFILE statement.
>
> > data envars;
> >    length name $32 value $1024;
> >    command = 'SET';
> >    infile dummy pipe filevar=command dlm='=' truncover end=eof
> > lrecl=2048;
> >    do while(not eof);
> >       input name value $char1024. ;
> >       output;
> >    end;
> >    stop;
> >    keep name value;
> > run;
>
> > On Jul 29, 7:29 am, "data _null_;" <datan...(a)gmail.com> wrote:
>
> > > 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;- Hide quoted text -
>
> > - Show quoted text -
>
> Where if the value if the ENV variable contains an equal sign?
>
> options set=tom 'this has = equal sign and another =';

The $CHAR format will "eat" the delimiters.

15 data _null_;
16 set ;
17 if index(value,'=');
18 put (var value) (=);
19 run;

var=_ value=PS1='[$PWD]->'
var=aaa value=this=that
From: data _null_; on
On Jul 31, 7:45 am, Tom Abernathy <tom.aberna...(a)gmail.com> wrote:
> On Jul 31, 7:25 am, "data _null_;" <datan...(a)gmail.com> wrote:
>
>
>
>
>
> > On Jul 30, 10:29 pm, Tom Abernathy <tom.aberna...(a)gmail.com> wrote:
>
> > > You can simplify the input code by using the = as a delimiter on the
> > > INFILE statement.
>
> > > data envars;
> > >    length name $32 value $1024;
> > >    command = 'SET';
> > >    infile dummy pipe filevar=command dlm='=' truncover end=eof
> > > lrecl=2048;
> > >    do while(not eof);
> > >       input name value $char1024. ;
> > >       output;
> > >    end;
> > >    stop;
> > >    keep name value;
> > > run;
>
> > > On Jul 29, 7:29 am, "data _null_;" <datan...(a)gmail.com> wrote:
>
> > > > 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;- Hide quoted text -
>
> > > - Show quoted text -
>
> > Where if the value if the ENV variable contains an equal sign?
>
> > options set=tom 'this has = equal sign and another =';
>
> The $CHAR format will "eat" the delimiters.
>
> 15   data _null_;
> 16    set ;
> 17    if index(value,'=');
> 18    put (var value) (=);
> 19   run;
>
> var=_ value=PS1='[$PWD]->'
> var=aaa value=this=that- Hide quoted text -
>
> - Show quoted text -

I see, I did not notice $CHAR and truncover and the rest. Sort is 6
of 1 half dozen wouldn't you say. :-)