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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 337 views
  • 1 like
  • 2 in conversation