proc sql+count

  • Follow


Hi all,

I am submitting the following code ..i get wrong values for the count of actual
....

data try1;
input FAcility_RK ITEM_RK DEMAND_DT mmddyy10. ACTUAL PREDICT;
format DEMAND_DT date9.;
cards;
40 121 10/1/2010 . 0
40 234 10/1/2008 0 0
40 234 1/1/2009 0 0
40 234 4/1/2009 0 0
40 234 7/1/2009 0 0
40 234 10/1/2009 . 0
40 234 1/1/2010 . 0
40 234 4/1/2010 . 0
40 234 7/1/2010 . 0
40 234 10/1/2010 . 0
40 291 4/1/2009 6 6
40 291 7/1/2009 0 0
40 291 10/1/2009 . 0
40 291 1/1/2010 . 0
40 291 4/1/2010 . 0
40 291 7/1/2010 . 0
40 291 10/1/2010 . 0
40 301 10/1/2008 0 0
40 301 1/1/2009 0 0
40 301 4/1/2009 0 0
40 301 7/1/2009 0 0
;
run;
proc print;
run;
proc sql;
 create table test78 as
    select FAcility_RK,ITEM_RK,DEMAND_DT ,ACTUAL,PREDICT,count(ACTUAL)
as calc
 from try1 group by FAcility_RK,ITEM_RK;
 quit;
output is ..

FAcility_RK ITEM_RK DEMAND_DT ACTUAL PREDICT calc
40 121 10/1/2010  0 0
40 234 10/1/2009  0 4
40 234 1/1/2010  0 4
40 234 1/1/2009 0 0 4
40 234 10/1/2010  0 4
40 234 7/1/2010  0 4
40 234 7/1/2009 0 0 4
40 234 10/1/2008 0 0 4
40 234 4/1/2009 0 0 4
40 234 4/1/2010  0 4
40 291 1/1/2010  0 2
40 291 4/1/2010  0 2
40 291 10/1/2009  0 2
40 291 7/1/2009 0 0 2
40 291 4/1/2009 6 6 2(y do iget 2 instead of 1)
40 291 10/1/2010  0 2
40 291 7/1/2010  0 2
40 301 7/1/2009 0 0 4
40 301 4/1/2009 0 0 4
40 301 1/1/2009 0 0 4
40 301 10/1/2008 0 0 4

plz guide me where  i am doing wrong.

Thanks all
0
Reply peesari.mahesh (114) 1/6/2010 10:14:05 AM

Hi,

you get 2 as the value for calc as count(ACTUAL) is counting every non-missing value of ACTUAL.
In your case that is 6 and 0 (and not ".").

Regards,
Marianne



On Wed, 6 Jan 2010 05:14:05 -0500, SUBSCRIBE SAS-L Joe H. Smith
<peesari.mahesh@GMAIL.COM> wrote:

>Hi all,
>
>I am submitting the following code ..i get wrong values for the count of actual
>...
>
>data try1;
>input FAcility_RK ITEM_RK DEMAND_DT mmddyy10. ACTUAL PREDICT;
>format DEMAND_DT date9.;
>cards;
>40 121 10/1/2010 . 0
>40 234 10/1/2008 0 0
>40 234 1/1/2009 0 0
>40 234 4/1/2009 0 0
>40 234 7/1/2009 0 0
>40 234 10/1/2009 . 0
>40 234 1/1/2010 . 0
>40 234 4/1/2010 . 0
>40 234 7/1/2010 . 0
>40 234 10/1/2010 . 0
>40 291 4/1/2009 6 6
>40 291 7/1/2009 0 0
>40 291 10/1/2009 . 0
>40 291 1/1/2010 . 0
>40 291 4/1/2010 . 0
>40 291 7/1/2010 . 0
>40 291 10/1/2010 . 0
>40 301 10/1/2008 0 0
>40 301 1/1/2009 0 0
>40 301 4/1/2009 0 0
>40 301 7/1/2009 0 0
>;
>run;
>proc print;
>run;
>proc sql;
> create table test78 as
>    select FAcility_RK,ITEM_RK,DEMAND_DT ,ACTUAL,PREDICT,count(ACTUAL)
>as calc
> from try1 group by FAcility_RK,ITEM_RK;
> quit;
>output is ..
>
>FAcility_RK ITEM_RK DEMAND_DT ACTUAL PREDICT calc
>40 121 10/1/2010  0 0
>40 234 10/1/2009  0 4
>40 234 1/1/2010  0 4
>40 234 1/1/2009 0 0 4
>40 234 10/1/2010  0 4
>40 234 7/1/2010  0 4
>40 234 7/1/2009 0 0 4
>40 234 10/1/2008 0 0 4
>40 234 4/1/2009 0 0 4
>40 234 4/1/2010  0 4
>40 291 1/1/2010  0 2
>40 291 4/1/2010  0 2
>40 291 10/1/2009  0 2
>40 291 7/1/2009 0 0 2
>40 291 4/1/2009 6 6 2(y do iget 2 instead of 1)
>40 291 10/1/2010  0 2
>40 291 7/1/2010  0 2
>40 301 7/1/2009 0 0 4
>40 301 4/1/2009 0 0 4
>40 301 1/1/2009 0 0 4
>40 301 10/1/2008 0 0 4
>
>plz guide me where  i am doing wrong.
>
>Thanks all
0
Reply m.weires (5) 1/6/2010 1:44:23 PM


1 Replies
257 Views

(page loaded in 0.032 seconds)

Similiar Articles:













7/29/2012 7:38:22 AM


Reply: