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

Hi,

 

I have this set of data

ID_A          COL_ID        AMOUNT_A  AMOUNT_B
1                  1_1                       100               110
1                   1_2                     200                210
1                  1_3                      200              210
1                   1_4                      300              310
1                    1_5                      300              310
2                    2_1                        50               55
3                     3_1                       60               65

 

The rows 2 / 3 and 4 / 5 are duplicates in all fields apart from field COL_ID. In these cases, I want to extract the first row i.e.

the following output.

 

ID_A   COL_ID   AMOUNT_A      AMOUNT_B
1         1_1        100                        110
1          1_2        200                      210
1         1_4        300                      310
2         2_1          50                        55
3        3_1           60                        65

 

Is this possible?

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Try:

proc sort data=have;
by ID_A amount_a amount_b;
run;

data want;
set have;
by ID_A amount_a amount_b;
if first.amount_b;
run;

proc sort data=want;
by ID_A col_id;
run;

View solution in original post

2 REPLIES 2
Astounding
PROC Star
Try:

proc sort data=have;
by ID_A amount_a amount_b;
run;

data want;
set have;
by ID_A amount_a amount_b;
if first.amount_b;
run;

proc sort data=want;
by ID_A col_id;
run;
cmemtsa
Quartz | Level 8
It works. Thank you.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 873 views
  • 0 likes
  • 2 in conversation