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
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.
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
> 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;
> data want;
> set have;
> I tested this approach against the array solution, and it ran in half the
> time, and with half the CPU usage.
> 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 ;
> >I am getting an error term. What is the mistake that I am making?
> > Randy