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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

4 REPLIES 4
GraphGuy
Meteorite | Level 14

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;

MikeZdeb
Rhodochrosite | Level 12

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;

Linlin
Lapis Lazuli | Level 10

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;

John70
Calcite | Level 5

Thanks All  !

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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