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

Hello,

 

I expect to get the largest DEGREE per 'HRM_L2, TYPE' group. If there are two same largest number of 'DEGREE' then I expect to keep all of them(even they are the missing value). 

 

by using the following table as an example,

HRM_L2PERSON_CTRY_CODETYPEDEGREE
AB 1 
ABUS16
ABGB12
CCUS2 
CCGB2 
DFCA42
DFGB42
DFDE42

I expect to get 

HRM_L2PERSON_CTRY_CODETYPEDEGREEnote
ABUS16it is the largest number of 'AB 1' group
CCUS2 I expect to keep both of them even they are the missing value
CCGB2  
DFCA42I expect to keep all of them if the largest number of DEGREE of this group are the same
DFGB42 
DFDE42 

Could you please give me some suggestion about this?

thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Look into Proc Rank.

 

Or here a data step approach:

proc sort data=sashelp.cars out=work.cars;
  by make type DESCENDING cylinders;
run;

data want;
  set cars;
  by make type;
  retain _cylinders;
  if first.type then _cylinders=cylinders;
  else if _cylinders ne cylinders then delete;
run;

 

Or SQL:

proc sql;
  create table want as
  select *
  from sashelp.cars
  group by make, type
  having max(cylinders)=cylinders
  ;
quit;

 

And last but not least:

If you're after code for your sample data then please provide such sample data via a working and tested SAS data step posted into a code window. Help us to help you.

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

Look into Proc Rank.

 

Or here a data step approach:

proc sort data=sashelp.cars out=work.cars;
  by make type DESCENDING cylinders;
run;

data want;
  set cars;
  by make type;
  retain _cylinders;
  if first.type then _cylinders=cylinders;
  else if _cylinders ne cylinders then delete;
run;

 

Or SQL:

proc sql;
  create table want as
  select *
  from sashelp.cars
  group by make, type
  having max(cylinders)=cylinders
  ;
quit;

 

And last but not least:

If you're after code for your sample data then please provide such sample data via a working and tested SAS data step posted into a code window. Help us to help you.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 421 views
  • 1 like
  • 2 in conversation