BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
podarum
Quartz | Level 8

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

FriedEgg
SAS Employee

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;

podarum
Quartz | Level 8

Thanks FriedEgg, very interesting approach.. And I had no idea the usage of coalesce, its so usefull.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 2897 views
  • 0 likes
  • 5 in conversation