[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Simple sum in proc sql
From:       xlr82sas <xlr82sas () AOL ! COM>
Date:       2010-01-30 2:08:34
Message-ID: 92978483-5ea1-4951-b406-fa78e3009854 () h9g2000prn ! googlegroups ! com
[Download RAW message or body]

HI

I like Joe's solution

Minor simplification. You don't need the _n_=1 by 1?

data suma;
xsum=0;
ysum=0;
do  until (eof);
    set t end=eof;
    xsum = xsum+x;
    ysum = ysum+y;
end;
eof=0;
do  until (eof);
    set t end=eof;
    output;
end;
run;







On Jan 29, 9:22 am, snoopy...@GMAIL.COM (Joe Matise) wrote:
> Data step will be easier.
>
> data t;
>   input t $2.  x y ;
> datalines;
> A  20   30
> B  30   20
> C  30   .
> ;;;;
> Run ;
>
> data sum;
> xsum=0;
> ysum=0;
> do _n_ = 1 by 1 until (eof);
>     set t end=eof;
>     xsum = xsum+x;
>     ysum = ysum+y;
> end;
> eof=0;
> do _n_ = 1 by 1 until (eof);
>     set t end=eof;
>     output;
> end;
> run;
>
> The problem in SQL is the sum function intentionally disregards missings, so
> it's a bit easier to do it in data step where you can use simple + operator.
>
> -Joe
>
> On Fri, Jan 29, 2010 at 11:18 AM, SAS_learner <procconte...@gmail.com>wrote:
>
>
>
> > data t;
> >   input t $2.  x y ;
> > A  20   30
> > B  30   20
> > C  30   .
> > ;;;
> > Run ;
>
> > Output dataset is sum of X and Y
>
> > T  X    y    X_Sum    Y_Sum
> > A 20  30     80          .
> > B 30  20     80
> > C 30          80
>
> > Hello all I am doing a simple sum using proc Sql using sum function, it is
> > giving me required results as expected but because of special purposes I
> > want to make my total missing if one of the (A B C ) are missing  as
> > missing. I know I can do this simply by transposing and adding them and put
> > it back. What I am looking is if it is possible to do with in proc sql step
> > or a data step without transpose and merging the datasets.
>
> > thanks
> > SL- Hide quoted text -
>
> - Show quoted text -
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic