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

Hello everybody,

 

I have a sample data sets as below,

 

If a customer default within that month, then the ID variable are multiplying. I would like to get the highest default value. I mean that if my target_flg variable is 1 then I need to take the that row (value 1.) Can somebody help me about it, please?

 

Data Have;
Length ID 8 YearMonth 8 Date 8 Target 8;
Infile Datalines Missover;
Input ID YearMonth Date Target;
Format Date Date9.;
Datalines;
1 201410 20000 0
1 201410 20010 0
1 201410 20015 0
1 201410 20020 1
2 201410 20019 0
2 201410 20013 1
3 201410 20017 1
4 201410 20022 0
5 201410 20012 0
5 201410 20016 1
;

Desired Data set;

 

DesiredTable.png

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
Data Have;
Length ID 8 YearMonth 8 Date 8 Target 8;
Infile Datalines Missover;
Input ID YearMonth Date Target;
Format Date Date9.;
Datalines;
1 201410 20000 0
1 201410 20010 0
1 201410 20015 0
1 201410 20020 1
2 201410 20019 0
2 201410 20013 1
3 201410 20017 1
4 201410 20022 0
5 201410 20012 0
5 201410 20016 1
;

proc sql;
select *
from have
group by id
having target=max(target)
order by id,target;
quit;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
Data Have;
Length ID 8 YearMonth 8 Date 8 Target 8;
Infile Datalines Missover;
Input ID YearMonth Date Target;
Format Date Date9.;
Datalines;
1 201410 20000 0
1 201410 20010 0
1 201410 20015 0
1 201410 20020 1
2 201410 20019 0
2 201410 20013 1
3 201410 20017 1
4 201410 20022 0
5 201410 20012 0
5 201410 20016 1
;

proc sql;
select *
from have
group by id
having target=max(target)
order by id,target;
quit;
novinosrin
Tourmaline | Level 20

The above assumes GOOD customers do not have duplicate records

 

And does your default ID always have 1 in the last record  as neatly sorted as your sample suggests?

 

if yes

 

data want;
set have;
by id;
if last.id;
run;

should suffice

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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