Date: Sat, 14 Jun 2008 23:36:25 GMT
Reply-To: Lou <lpogoda@VERIZON.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Lou <lpogoda@VERIZON.NET>
Subject: Re: SAS operation generating missing values
"sphinx0101" <sphinx0101@gmail.com> wrote in message
news:fe8657f3-eb0c-4d56-8d70-79808c9a42b4@25g2000hsx.googlegroups.com...
> On Jun 14, 5:13 pm, hs AT dc-sug DOT org ("Howard Schreier)" wrote:
> > On Sat, 14 Jun 2008 13:12:03 -0700, sphinx0101 <sphinx0...@GMAIL.COM>
wrote:
> > >Hi All,
> > >I am running into a strange problem with SAS. I imported this excel
> > >file into SAS without any problem. Now when I am running an operation
> > >I am getting missing values for the first observation. I created a
> > >simple dataset which helped me to see the nature of the problem as
> > >follows
> >
> > >x y
> > >10 5
> > >20 2
> > >30 4
> > >40 8
> >
> > >Now when I am trying to create a simple varible z = x/y I am getting
> > >the following
> >
> > >x y z
> > >10 5 .
> > >20 2 2
> > >30 4 10
> > >40 8 7.5
> >
> > >As you can see the problem is that SAS is doing the calculation and
> > >entering the new variable value with respect to the second
> > >observation. I am not sure why this is happening. Any help would be
> > >greatly acknowledged.
> >
> > Any help is unlikely, unless you post your code.
>
> I am sorry. My code was
>
> data new;
> z = x/y;
> set mylib.new;
> run;
>
> I am not sure why this problem occured, as you can see this was a
> simple exercise.
Apparently not as simple as you think. The first time the calculation is
made, you haven't read any data yet, so x is missing, y is missing, and of
course z will be missing. And that's what gets written to the output
dataset. The second time the calculation executes, you're working with data
from the first observation, so z is correctly calculated as 2. Then you
read in the second observation and write the output.
To correct the situation the SET statement should come before the "z=x/y"
statement.
|