LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 17 Feb 2000 21:42:47 -0600
Reply-To:     shiling@math.wayne.edu
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Shiling Zhang <shiling@MATH.WAYNE.EDU>
Organization: Wayne State University
Subject:      Re: re-order variables
Comments: To: peter.crawford@DB.COM
Content-Type: text/plain; charset=us-ascii

Peter & _all_;

Retain statement is a saftest way to re-order a variable list if it is BEFORE a set statement and all variables are from the data set. However, any attribute statements(length, label, format, informat) can re-order a variable list too if they are BEFORE a set statement. None of them initialize any values. But they may need more information may have side effects. Unfortunately, the re-order function of retain is never documented in SAS manual. I guess it is a by-product of retain statement. Another difference is that any uninitialized variable in a retain statement will not be created in PDV, and hence, an output data set. And also SAS will issue a note. So retain is the best way in this context.

84 data t2; 85 set t1; 86 retain x y; 87 run;

NOTE: Variable Y is uninitialized. NOTE: The data set WORK.T2 has 1 observations and 1 variables. NOTE: The DATA statement used 0.16 seconds.

88 data t2; 89 length z 8; 90 set t1; 91 retain x y; 92 run;

NOTE: Variable Z is uninitialized. NOTE: Variable Y is uninitialized. NOTE: The data set WORK.T2 has 1 observations and 2 variables. NOTE: The DATA statement used 0.16 seconds. 93 94 data t2; 95 format z best.; 96 set t1; 97 retain x y; 98 run;

NOTE: Variable Z is uninitialized. NOTE: Variable Y is uninitialized. NOTE: The data set WORK.T2 has 1 observations and 2 variables. NOTE: The DATA statement used 0.22 seconds.

A Keep statement just marks variables in PDV like the other post pointed out, no more no less. A Keep statement can be put anywhere in a data step and it will have the same function. When Keep statement refers to a variable that is not on PDV(not internal variable), the variable will never be created in a output dataset. SAS will issue a warning message.

99 data t2; 100 format z best.; 101 set t1; 102 keep x y z; 103 run;

NOTE: Variable Z is uninitialized. WARNING: The variable Y in the DROP, KEEP, or RENAME list has never been referenced.

NOTE: The data set WORK.T2 has 1 observations and 2 variables. NOTE: The DATA statement used 0.16 seconds.

Peter Crawford wrote:

> perhaps it is because the RETAIN statement can assign initial values that the > variables referred in this way can reserve their position/space in the data step > data vector > KEEP has no power to create or assign a value. > > Datum: 17.02.2000 20:39 > An: SAS-L@listserv.uga.edu > > Antwort an: taf2@is8.nyu.edu > > Betreff: Re: re-order variables > Nachrichtentext: > > To SAS-L: > > Could anyone explain why RETAIN changes the variable order in this > situation, whereas KEEP does not? In other words, the following code > will change the variable order in the dataset: > > data test2; > RETAIN mailname series; > set test; > run; > > but this code will not: > > data test2; > KEEP mailname series; > set test; > run; > > Thanks! > > --Tom > Tom Frenkel <taf2@is8.nyu.edu> > http://pages.nyu.edu/~taf2


Back to: Top of message | Previous page | Main SAS-L page