Newsgroups: bit.listserv.sas-l
Date:         Wed, 11 Nov 1992 11:54:03 PST
Reply-To:     Thomas M Skinner <Thomas_M_Skinner@CCM.HF.INTEL.COM>
From:         Thomas M Skinner <Thomas_M_Skinner@CCM.HF.INTEL.COM>
Subject:      Re: VIEWs & RENAMEs
Comments: To: Bert_Cave@ccm.hf.intel.com, SAS-L@uga.cc.uga.edu

                                                       Folsom, California
                                                       Sunny, Cool High of 65


Dear SAS-Lers:

Howard Schreier Writes:

>CONTENT:  Question/Comment
>SUMMARY:  Problem with DATA step VIEWs and RENAMEs
>REL/PLTF: 6.07 MVS

>I encounter some strange results involving  the  interaction
>of KEEPs and RENAMEs pertaining to a DATA step VIEW.  Here I
>create a view which should return one  observation  and  one
>variable:

>12            data view (keep = newname) / view=view;
>13            rename oldname = newname;
>14            oldname = 1;
>NOTE: DATA STEP view saved on file WORK.VIEW.
>NOTE: The DATA statement used 0.01 CPU seconds and 3575K.

>But when I try to print it, nothing is there:

>15            proc print;
>NOTE: No variables in data set WORK.VIEW.

>I get the expected results if I leave off the VIEW option or
>if  I  use  a  KEEP statement (KEEP OLDNAME;) instead of the
>KEEP data set option.


Reply:

Howard, I think you're on to something here..

It also has to do with whether the rename occurs as a "SET" statement option,
or whether it is effected by a RENAME statement.

First some background:


The Data Step View (DSV) is created by compiling the data step statements .
When the DSV is referenced, the statements are executed. (Tech Report P-222 pp
149-155).  The Program Data Vector (PDV) is constructed during the compile
phase, as is the dataset descriptor. (SAS Language Reference V6, pp 15-16).

Executable statements result in some action during the individual iterations of
the data step. Declarative statements supply information to the SAS system and
take effect when the system compiles program statements.  The RENAME, and KEEP,
statements are listed as a declarative statements. (SAS Language Reference V6,
pp 44-45).

Hence one would expect the declarative RENAME statement to generate a new
variable name during the compile and construction of the view.

Well.. it doesn't...

As a demonstration of this, I built the following test code:
I also test for the declarative statement KEEP as well, which does perform
properly.

Note: Dataset names appended with "1" indicate a view option.
      Dataset names appended with "2" indicate no view option.

      I use the set option to bring in data from a dataset "TEST" that has two
variables, to test the keep option.


 RENAME as a Set statement option
 KEEP as a Data statement option.

 NOTE: At top.
 639  data test; old = 1; dum = 1;

 NOTE: The data set WORK.TEST has 1 observations and 2 variables.
 NOTE: The DATA statement used 0.01 CPU seconds and 6500K.

 640  data test1 (
 641              keep   = new
 642             )
 643             / view  = test1
 644             ;
 645       set test (
 646                 rename = (old = new)
 647                )
 648                ;
 649  run;

 NOTE: DATA STEP view saved on file WORK.TEST1.
 NOTE: The original source statements cannot be retrieved from a stored DATA
       STEP view nor will a stored DATA STEP view run under a different
       release of the SAS system or under a different operating system.

       Please be sure to save the source statements for this DATA STEP view.
 NOTE: The DATA statement used 0.01 CPU seconds and 6500K.

 650  proc print data = test1; run;



All's well here..




 NOTE: The view WORK.TEST1.VIEW used 0.04 CPU seconds and 6500K.
 NOTE: The PROCEDURE PRINT used 0.00 CPU seconds and 6500K.

 651  data test2 (
 652              keep   = new
 653             )
 654  /*         / view  = test2     <--- view not created */
 655             ;
 656       set test (
 657                 rename = (old = new)
 658                )
 659                ;
 660  run;

 NOTE: The data set WORK.TEST2 has 1 observations and 1 variables.
 NOTE: The DATA statement used 0.01 CPU seconds and 6500K.

 661  proc print data = test2; run;


NOTE: The PROCEDURE PRINT used 0.00 CPU seconds and 6500K.


Same here, just demonstrating consistency and no VIEW option effect.



RENAME STATEMENT ....
KEEP as a Data statement option.



 662  data test1b (
 663                keep   = new
 664              )
 665              / view  = test1b
 666              ;
 667       set test;
 668       rename old = new;
 669  run;

 NOTE: DATA STEP view saved on file WORK.TEST1B.
 NOTE: The original source statements cannot be retrieved from a stored DATA
       STEP view nor will a stored DATA STEP view run under a different
       release of the SAS system or under a different operating system.
       Please be sure to save the source statements for this DATA STEP view.
 NOTE: The DATA statement used 0.01 CPU seconds and 6500K.

 670  proc print data = test1b; run;

 NOTE: No variables in data set WORK.TEST1B.
 NOTE: The view WORK.TEST1B.VIEW used 0.03 CPU seconds and 6500K.
 NOTE: The PROCEDURE PRINT used 0.00 CPU seconds and 6500K.


Same result Howard got... RENAME statement has no effect.



 671  data test2b(
 672              keep   = new
 673             )
 674  /*         / view  = test2b    <--- view not created */
 675             ;
 676       set test;
 677       rename old = new;
 678  run;

 NOTE: The data set WORK.TEST2B has 1 observations and 1 variables.
 NOTE: The DATA statement used 0.01 CPU seconds and 6500K.
 679  proc print data = test2b; run;

 NOTE: The PROCEDURE PRINT used 0.00 CPU seconds and 6500K.


Note: same result Howard got... The data step without the VIEW performed as
expected.  The RENAME statement executed.



RENAME as a SET statement option ....
KEEP STATEMENT


 680  data test1c
 681             / view  = test1c
 682             ;
 683       set test (
 684                 rename = (old = new)
 685                )
 686                ;
 687       keep new;
 688  run;

 NOTE: DATA STEP view saved on file WORK.TEST1C.
 NOTE: The original source statements cannot be retrieved from a stored DATA
       STEP view nor will a stored DATA STEP view run under a different
       release of the SAS system or under a different operating system.
       Please be sure to save the source statements for this DATA STEP view.
 NOTE: The DATA statement used 0.01 CPU seconds and 6500K.
 689  proc print data = test1c; run;

 NOTE: The view WORK.TEST1C.VIEW used 0.04 CPU seconds and 6500K.
 NOTE: The PROCEDURE PRINT used 0.00 CPU seconds and 6500K.


Everything fine here...


 690  data test2c
 691  /*         / view  = test2c     <--- view not created */
 692             ;
 693       set test (
 694                 rename = (old = new)
 695                )
 696                ;
 697       keep new;
 698  run;

 NOTE: The data set WORK.TEST2C has 1 observations and 1 variables.
 NOTE: The DATA statement used 0.01 CPU seconds and 6500K.
                                                                              4
 699  proc print data = test2c; run;
 NOTE: The PROCEDURE PRINT used 0.00 CPU seconds and 6500K.                   4


Fine here too....


So to summarize, although the RENAME STATEMENT is said to be DECLARATIVE, that
is to take effect at compilation, these results dispute that.

The KEEP statement does perform as expected.

I suppose we should investigate the use of other declarative statements as
well..such as Format, Informat, Length, etc...

Will report to EMITS..


Intel-Insider,

Tom Skinner
==============================================================================
T.M. Skinner                     Internet: Thomas_M_Skinner@ccm.hf.intel.com
Sr. SAS Technical Support            Mail: 1900 Prairie City Rd. MS FM1-102
Intel Corporation                          Folsom, CA 95630
==============================================================================
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU