BookmarkSubscribeRSS Feed
gsaba
Calcite | Level 5

Hello guys,

 

I need your help with a little issue here:

 

I had a big database, then wrote Proc Sort, with some criterias and now have this:

 

id          date               cam          amount

4701      11JAN2018     1             $30.00
4701      09JAN2018     0             $30.00
16044    16JAN2018     1             $40.00
28563    30JAN2018     0             $10.00

 

this is the proc sort I wrote before:

 

proc sort data=lib.RESULT out=lib.RESULT

nodupkey; by id cam;

RUN;

 

the question is that now I want to add something in my proc sort to tell sas (if id is duplicated), select those values when date is smaller and 'cam' is 1. these are the priorities. how can I do that? can anobody help?

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You would need two steps:

proc sort data=lib.result; 
  by id cam date;
run;
data want;
  set lib.result;
  by id;
  if first.id and cam=1;
run;

Note, I have only done this based on the test data you provided (and provided not in a datastep!!).  Would need to see some actual descriptive test data in the form of a datastep and what you want to see out at the end.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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