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

sort the input12dataset .First by number in ascending and second by income in descending order.Using input12 dataset with by group processing create test data from the input12 dataset

test 2 dataset must contain only one observation with highest income from each group of distint number value

MY CODE:

proc sort data=input12 out=test;

by number descending income;

run;

data test;

set test;

by number;

if first.number;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

Works, but I would specify the sorting order in want to make sure

data have;
infile datalines;
input number income;
datalines;
1 100
1 130
1 120
1 110
2 250
2 200
3 300
4 420
4 410
4 430
4 440
4 450
5 530
5 520
5 510
5 500
8 800
;
run;

proc sort data=have out=haves;
   by number descending income;
run;

data want;
set haves;
by number descending income;
if first.number;
run;
________________________

- Cheers -

View solution in original post

1 REPLY 1
Oligolas
Barite | Level 11

Works, but I would specify the sorting order in want to make sure

data have;
infile datalines;
input number income;
datalines;
1 100
1 130
1 120
1 110
2 250
2 200
3 300
4 420
4 410
4 430
4 440
4 450
5 530
5 520
5 510
5 500
8 800
;
run;

proc sort data=have out=haves;
   by number descending income;
run;

data want;
set haves;
by number descending income;
if first.number;
run;
________________________

- Cheers -

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
  • 469 views
  • 0 likes
  • 2 in conversation