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 -

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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