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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 733 views
  • 0 likes
  • 2 in conversation