Sorry , I think I was getting 0's because I had none missing.. for a second I was thinking I was only seeing the perecentage of missing... All clear now.. thanks
data foo;
input (store product) ($) v1-v4;
cards;
A A1 5 . 6 3
A A1 7 6 0 9
A A1 6 . 4 .
A A2 . 5 3 3
A A2 5 4 7 5
B B1 3 . 0 8
B B1 . 5 6 7
B B2 . 5 8 9
;
run;
data bar;
set foo;
by store product;
if first.product then do;
cnt=0;
nmiss=0;
end;
cnt+4;
nmiss+(coalesce(v1,0)=0) +
(coalesce(v2,0)=0) +
(coalesce(v3,0)=0) +
(coalesce(v4,0)=0);
if last.product then do;
pctmiss=nmiss/cnt;
output;
end;
keep store product pctmiss;
run;
proc sql;
create table _bar as
select store,
product,
( sum( (coalesce(v1,0)=0) +
(coalesce(v2,0)=0) +
(coalesce(v3,0)=0) +
(coalesce(v4,0)=0) ) ) /
( count(*)*4 ) as pctmiss
from foo
group by store,product;
quit;
Thanks FriedEgg, very interesting approach.. And I had no idea the usage of coalesce, its so usefull.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.