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 (April 2012, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 16 Apr 2012 15:53:38 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: How to change many missing variables to 0 in a single data
              step
Comments: To: s.lassen@post.tele.dk
In-Reply-To:  <201204160600.q3G4NUMG032728@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="Windows-1252"

Works great if your variable names are VarA1 - VarA50... Not so great once you have to use it on real data where the names arent standardized... YOu will either have to hand type them in a list or use another macro to retrieve the variable names. The array method doesn't need you to find or explicitly write them out.

Toby Dunn

If you get thrown from a horse, you have to get up and get back on, unless you landed on a cactus; then you have to roll around and scream in pain. “Any idiot can face a crisis—it’s day to day living that wears you out” ~ Anton Chekhov

> Date: Mon, 16 Apr 2012 02:00:17 -0400 > From: s.lassen@POST.TELE.DK > Subject: Re: How to change many missing variables to 0 in a single data step > To: SAS-L@LISTSERV.UGA.EDU > > Randy, > You can solve this with an array - but as you state that you have a large > number of rows in your table, a macro is probably more efficient, e.g.: > > %macro miss2zero; > %local i; > %do i=1 %to 50; > if VarA&i=. then VarA&i=0; > %end; > %mend; > > data want; > set have; > %miss2zero; > run; > > I tested this approach against the array solution, and it ran in half the > time, and with half the CPU usage. > > Regards, > Søren > > > On Sun, 15 Apr 2012 10:02:36 -0400, Randy <RANDISTAN69@HOTMAIL.COM> wrote: > > >I have many variables and some of the values are missing. I want to > >change the missing values to 0 in a single data step. > > > >The code I have written is: > >Data want ; set have; > >if VarA1 - VarA50 = . then VarA1 - VarA50 = 0 ; > >run; > > > >I am getting an error term. What is the mistake that I am making? > > > > Randy


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