Data visualization with SAS programming

how to pick up more than 1 max values

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

how to pick up more than 1 max values

Dear All, how to pick up more than 1 max values in a column and flag them in another column?  see attached code.  thanks!

Attachment

Accepted Solutions
Solution
‎07-19-2012 03:09 PM
Super Contributor
Posts: 1,636

Re: how to pick up more than 1 max values

The more the merrier:

data sample;
    input id x;
datalines;
18  1
18  1
18  2
18  1
18  2
369 2
369 3
369 3
361 1
;
proc sort ;
by id descending  x;
run;

data want ;
  retain xmax;
  set sample;
  by id;
  xmax=ifn(first.id,x,xmax);
  xmax=ifn(x=xmax,xmax,.);
proc print; run;

View solution in original post


All Replies
SAS Employee
Posts: 967

Re: how to pick up more than 1 max values

Hmm ... not really a Graph question, but here is one way to do it...

data sample;
    input id x;
datalines;
18  1
18  1
18  2
18  1
18  2
369 2
369 3
369 3
361 1
;
run;

proc sql;
create table sample as
select sample.*, max(x) as group_max
from sample
group by id;
quit; run;

data sample (drop=group_max); set sample;
if x=group_max then xmax=x;
run;

Valued Guide
Posts: 763

Re: how to pick up more than 1 max values

hi ... another SQL idea ...

proc sql;

create table sample as

select *,

case

   when x eq max(x) then max(x)

   else .

end as xmax

from sample

group by id;

quit;

Solution
‎07-19-2012 03:09 PM
Super Contributor
Posts: 1,636

Re: how to pick up more than 1 max values

The more the merrier:

data sample;
    input id x;
datalines;
18  1
18  1
18  2
18  1
18  2
369 2
369 3
369 3
361 1
;
proc sort ;
by id descending  x;
run;

data want ;
  retain xmax;
  set sample;
  by id;
  xmax=ifn(first.id,x,xmax);
  xmax=ifn(x=xmax,xmax,.);
proc print; run;

Contributor
Posts: 28

Re: how to pick up more than 1 max values

Thanks All  !

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 237 views
  • 6 likes
  • 4 in conversation