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 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 27 Feb 2007 19:54:58 -0500
Reply-To:     "data _null_;" <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_;" <datanull@GMAIL.COM>
Subject:      Re: RECODE MISSING
Comments: To: Mike Rhoads <RHOADSM1@westat.com>
In-Reply-To:  <403593359CA56C4CAE1F8F4F00DCFE7D07295335@MAILBE2.westat.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Another easy way that overcomes the data type problem is to use UPDATE and Howard Schreier's nice frame building technique. No arrays needed, therefore no type problems. You do need a unique key for the BY statement.

data work.test; do id = 1 to 10; output; end; retain x_1 x_hello x_ . x_2 ' '; retain y_1 y_x help .; retain notmissing x y z 20; run; data work.test90; set work.test(keep=id); if 0 then set work.test(keep=x_:); retain _numeric_ 90 _character_ '90'; run; data work.test90; update work.test90 work.test; by id; run; proc print; run;

On 2/27/07, Mike Rhoads <RHOADSM1@westat.com> wrote: > This is a direct approach and should certainly work. There's a > theoretical disadvantage in terms of efficiency in that the > variable-name test is being done for every record and every variable. > If the number of variables and records is not too big, this is probably > not a significant practical problem. > > A way to avoid that would be to use two SELECT INTO statements in PROC > SQL to query the dictionary tables and construct two macro variables: > one containing a list of all numeric variables beginning with A_, and a > second containing all character variables beginning with A_. The macro > variables could then be used in the ARRAY statements, replacing the > _NUMERIC_ and _CHARACTER_ lists. > > Mike Rhoads > Westat > RhoadsM1@Westat.com > > -----Original Message----- > From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu] > On Behalf Of Ya Huang > Sent: Tuesday, February 27, 2007 3:37 PM > To: SAS-L@LISTSERV.UGA.EDU; Ran S > Cc: Ya Huang > Subject: Re: RECODE MISSING > > > /* recode the numeric variables */ > DO inum = 1 to dim(num_array); > if upcase(substr(vname(num_array(inum)),1,2))='A_' and > num_array{inum} IN (.,98) then num_array{inum}=998; > END; > > /* recode the character variables */ > Do ichar = 1 to dim(char_array); > if upcase(substr(vname(char_array(ichar)),1,2))='A_' and > char_array{ichar} IN ("98",".") then char_array > {ichar}="998"; > END; > > > > On Tue, 27 Feb 2007 15:27:55 -0500, Ran S <raan67@YAHOO.COM> wrote: > > >Thanks. Lookslike it works for numeric variables. I have a combination > of > >variables numeric and character and I am using following the code to > recode: > > > >ARRAY num_array{*} _NUMERIC_; > > ARRAY char_array{*} _CHARACTER_; > > > > /* recode the numeric variables */ > > DO inum = 1 to dim(num_array); > > if num_array{inum} IN (.,98) then num_array{inum}=998; > > END; > > > > /* recode the character variables */ > > Do ichar = 1 to dim(char_array); > > if char_array{ichar} IN ("98",".") then char_array > >{ichar}="998"; > > END; > > > > drop inum ichar; > > > >But Now I want to recode only A_ variables. > > > >Thanks! Ran >


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