Newsgroups: bit.listserv.sas-l
Date:         Wed, 11 Nov 1992 14:35:01 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[2]: VIEWs & RENAMEs
Comments: To: Bert_Cave@ccm.hf.intel.com, SAS-L@uga.cc.uga.edu

Dear SAS-Lers:

Rich Levin replies to Howard Schreier's mailing:


          >Page 173 of the SAS Language manual (Version 6 Reference) shows
          >the order of precedence of DROP, KEEP, and RENAME statements and
          >options. This documentation suggests that your code should work as
          >this precedence changes. I tested the same code above, but changed
          >"keep = newname" to "keep = oldname", and it worked fine.

          >I would guess that this change in precedence occurs because the
          >view only stores the compiled data step. Perhaps part of the
          >documented precedence relationship occurs at execution time?
          >Anyway, if you use KEEP and RENAME the same way, (either both KEEP=
          >and RENAME= or both KEEP and RENAME) then the precedence will
          >always occur as documented.

Reply:

Richard, You're right to point out the order of precedence.  In fact, the RENAME
"STATEMENT" enjoys a dual role:  The old name is used in other program
statements, and the new name is used in the output data set options, the
question that remains is whether the former property (old name used in program
statements) is in effect at compile rather than execution, and additionally
whether the KEEP statement or data statement option (KEEP=) has a role in all
this.  To test this I submitted the following:


 14   data test;
 15        old = 1 ;

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

 16   data test4 / view = test4;
 17        set test;
 18   keep new;
 19   rename old = new;

 NOTE: DATA STEP view saved on file WORK.TEST4.
 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 5062K.

 20   proc print data = test4; var new; run;

 ERROR: Variable NEW not found.  Note: in fact there are 0 varaibles in the set.


 NOTE: The view WORK.TEST4.VIEW used 0.04 CPU seconds and 5062K.
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: The PROCEDURE PRINT used 0.00 CPU seconds and 5062K.

Note: the order of the KEEP and RENAME statements has no effect here.
What's interesting here, is the KEEP STATEMENT did not generate a error or
warning.  The net result was the output dataset has no variables at all,
indicating again that the RENAME STATEMENT did not take effect, while the KEEP
did (even though the result of which was no variables kept).  A similar test
eliminating the KEEP statement resulted in a dataset with the new name,
indicating that the RENAME STATEMENT indeed has an effect in the VIEW, however
it is confounded, or somehow disabled by the KEEP, be it statement or option.

And if the audience out there isn't confounded yet, I'd be amazed...

So the moral of the story is:  If using a KEEP statement or KEEP= option in a
view with a corresponding newly named variable via RENAME, be sure to use the
RENAME= OPTION on the SET STATEMENT..and not the RENAME STATEMENT.  This
solution requires using the NEW name in all program statements. Obviously, there
is a loss of flexibility and functionality associated with this,
Soooooo..Perhaps SI can take a look at it.
'NUF SAID.

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
================================================================================